Skip to content

Use @JsonProperty(index) for sorting properties on serialization #2555

@cowtowncoder

Description

@cowtowncoder

Although property index was added in Jackson 2.4, and is used for some purposes (such as integer field id for protobuf), it is not yet (as of 2.10) used for ordering properties in other contexts. But it probably should be: there are already requests to use it for CSV headers, for example, and it seems reasonable that ordering would be based on combination of things so that:

  1. Explicit ordering (via @JsonPropertyOrder) would have highest priority
  2. @JsonProperty.index should be used after this
  3. Possible alphabetic ordering for things not covered by (1) or (2)

It may become necessary to allow NOT doing this, too (via MapperFeature), but let's start by assumption that index should be used.

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