Comments (5)
Thank you for the quick response. I understand your reasoning and there's no need for a fix. Please label this as a question and close it.
from json-schema-inferrer.
The cause of this behavior is this line:
Collectors.toSet()
uses a HashSet
under the hood and HashSet
does not guarantee ordering for obvious reasons.
I guess you can say this is intentional, because 2 JSON schema objects with different field orderings should be logically identical. I also wonder why you are having trouble writing tests. I think Jackson is smart enough to know that 2 JSON objects with different field orderings are considered equal. For those reasons, I don't really feel like "fixing" the issue, even though it's a very simple fix.
public static void main(String[] args) {
final ObjectNode o1 = JsonNodeFactory.instance.objectNode()
.put("a", 1)
.put("b", 2);
final ObjectNode o2 = JsonNodeFactory.instance.objectNode()
.put("b", 2)
.put("a", 1);
System.out.println(o1);
System.out.println(o2);
System.out.println(o1.equals(o2));
}
The above main method prints
{"a":1,"b":2}
{"b":2,"a":1}
true
from json-schema-inferrer.
There is a downstream effect when using this in conjunction with jsonschema2pojo, since it generates a @JsonPropertyOrder annotation using the sequence in the schema. Using a LinkedHashSet seems like a small price to pay for the predictability. But the tool is so immensely useful, I'm fairly sorry to even mention it. Congratulations on some really fine work, and if the property order keeps me awake at night, I'll submit my first ever (old and wise as I am) PR.
from json-schema-inferrer.
Fixed in 0.1.4.
from json-schema-inferrer.
Thanks! It must have been committed the day after I pulled. It's a really useful utility and gives a productivity boost. We have really huge JSON docs.
from json-schema-inferrer.
Related Issues (20)
- it will be better to provide a cli tool HOT 1
- Support for JSON Schema 2019-09 Spec HOT 1
- intelliJ gradle dependency failure HOT 2
- It is not parsed according to the original JSON field order HOT 1
- Not support const field. HOT 1
- There is no JsonNode's key in GenericSchemaFeatureInput. HOT 2
- JSON is a long type, but schema is an integer HOT 1
- Maven dependency-check displays json-schema-inferrer-0.1.4 as Critical because the vulnerability CVE-2021-3918 HOT 2
- The version of jackson-databind has a vulnerability
- [ Feature] Is there any way to generate random data with the json schema HOT 2
- Can you deploy the latest version to the Maven Repository? HOT 1
- Can you give items a default value when the array is empty? HOT 1
- Doesn't work with Java 8 HOT 2
- Upgrade on Draft version HOT 1
- Need JAR HOT 3
- $ref and $id HOT 1
- Build Errors. HOT 2
- How to generate a schema with "$id" and "$ref"? HOT 3
- State of the repo HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-schema-inferrer.