Skip to content

Use LinkedHashMap to preserve order of schema elements #395

Open
@JoshMcCullough

Description

@JoshMcCullough

Currently a HashMap is used, so the order of e.g. properties is not preserved. A simple change to use LinkedHashMap instead would preserve the schema designer's insertion order.

Example:

ObjectSchema.builder()
    .addProperty("one", ...)
    .addProperty("two", ...)
    .addProperty("three", ...);

The result in something like ...

{
  "properties": [
        "two": ...,
        "three": ...,
        "one": ...,
  ]
}

... where the properties are in an indeterminate order (based on the hash of the key). Preferably, the order would be preserved:

{
  properties: [
        one: ...,
        two: ...,
        three: ...,
  ]
}

Some would argue "no way man, the JSON spec specifically says that property order doesn't matter" (yeah, I lost that fight and here I am again for round 2), but I'd argue that the order being effectively random is far worse than the order being preserved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions