Skip to content

MapperFeature.SORT_PROPERTIES_ALPHABETICALLY is not respected for records #3900

@agavrilov76

Description

@agavrilov76

MapperFeature.SORT_PROPERTIES_ALPHABETICALLY is no longer respected by record method based JSON properties

Version information
2.15

To Reproduce

    final var mapper =
        Jackson.mapperBuilder()
            .enable(SerializationFeature.INDENT_OUTPUT)
            .enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY)
            .build();

    record R(String c, String b, String e) {

      @JsonProperty
      String a() {
        return "4";
      }
    }

    System.out.println(mapper.writeValueAsString(new R("1", "2", "3")));

Output:

  {
    "b" : "2",
    "c" : "1",
    "e" : "3",
    "a" : "4"
  }

The property 'a' in the example below comes at the last place:

Expected behavior
All record properties must be serialized the natural order

Metadata

Metadata

Assignees

No one assigned

    Labels

    will-not-fixClosed as either non-issue or something not planned to be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions