Skip to content

@JsonPropertyOrder not respected with defined attributes #91

@thrykol

Description

@thrykol

I've noticed that attributes in a POJO must be included first in the @JsonPropertyOrder annotation list in order for the other properties to be ordered.

It is my understanding that the properties in the ordered list take precedence while unlisted properties will follow the ordered properties in any order.

I am using version 2.3.1 from maven central.

In the test class

public class OrderTest
{
    private String a = "first";
    @JacksonXmlProperty(isAttribute = true)
    private String b = "attribute";
    private String c = "second";

    public static void main(String[] args)
        throws Exception
    {
        XmlMapper xmlMapper = new XmlMapper();
        xmlMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
        xmlMapper.writeValue(System.out, new OrderTest());
    }

    public String getA()
    {
        return a;
    }

    public String getB()
    {
        return b;
    }

    public String getC()
    {
        return c;
    }
}

annotating the class with either @JsonPropertyOrder({"a", "c"}) or @JsonPropertyOrder({"a", "c", "b"}) results in orderless output while the annotation @JsonPropertyOrder({"b","a", "c"}) orders properly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions