Giter Club home page Giter Club logo

Comments (5)

tharindu-nw avatar tharindu-nw commented on June 14, 2024 1

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.

slisaasquatch avatar slisaasquatch commented on June 14, 2024

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.

tcrg311 avatar tcrg311 commented on June 14, 2024

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.

slisaasquatch avatar slisaasquatch commented on June 14, 2024

Fixed in 0.1.4.

from json-schema-inferrer.

tcrg311 avatar tcrg311 commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.