Jackson 2.3.0 default serialization order

3,239 views
Skip to first unread message

Evan Brodie

unread,
Dec 9, 2013, 9:26:30 AM12/9/13
to jackso...@googlegroups.com
I am trying to upgrade the Jackson in my project from 2.2.2 to 2.3.0. I noticed that the serialization order of some of my classes have changed, which I discovered because of failing unit tests. In 2.3.0, when serializing a Java class's attributes to JSON, it appears that all attributes not marked with a @JsonProperty annotation are serialized first (in order that they appear), followed by all attributed marked with that annotation (in order that they appear from the top of the file). Whereas, in Jackson 2.2.2, the order doesn't appear to be as strict as I am experiencing.

Can anyone please confirm my findings? Where exactly can I find online documentation about the default/implicit serialization order of ObjectMapper? I came across the JavaDoc of this class (http://fasterxml.github.io/jackson-annotations/javadoc/2.3.0/com/fasterxml/jackson/annotation/JsonPropertyOrder.html), but I highly doubt it contains the information that I am looking for. I think that the JsonPropertyOrder annotation is for when I want to specify my own custom order.

Tatu Saloranta

unread,
Dec 9, 2013, 1:06:01 PM12/9/13
to jackso...@googlegroups.com
I would say that in absence of explicit declaration (via @JsonPropertyOrder), and general mechanisms (sort-alphabetically; Object Id and Type Id preceding other properties), there is no defined ordering. So ordering of properies is otherwise unspecified.

I can't think of obvious changes to ordering algorithm, except for one fix where sort-alphabetically was not being obeyed.

One thing to note is that Oracle did change behavior of JDK 7, such that previously stable ordering of methods and fields returned by Introspection become arbitrary. This means that there isn't much Jackson can do to try to retain declaration order (there is no way to obtain that info via JDK).

So: no intentional change was made between 2.2 and 2.3. Existing default ordering is based on simple traversal and ordering that JDK provides; and this has not been changed. One possibility is that when adding partial ordering (based on annotations) something may have changed wrt ordering of un-annotated properties.

-+ Tatu +-



On Mon, Dec 9, 2013 at 6:26 AM, Evan Brodie <ecb...@gmail.com> wrote:
I am trying to upgrade the Jackson in my project from 2.2.2 to 2.3.0. I noticed that the serialization order of some of my classes have changed, which I discovered because of failing unit tests. In 2.3.0, when serializing a Java class's attributes to JSON, it appears that all attributes not marked with a @JsonProperty annotation are serialized first (in order that they appear), followed by all attributed marked with that annotation (in order that they appear from the top of the file). Whereas, in Jackson 2.2.2, the order doesn't appear to be as strict as I am experiencing.

Can anyone please confirm my findings? Where exactly can I find online documentation about the default/implicit serialization order of ObjectMapper? I came across the JavaDoc of this class (http://fasterxml.github.io/jackson-annotations/javadoc/2.3.0/com/fasterxml/jackson/annotation/JsonPropertyOrder.html), but I highly doubt it contains the information that I am looking for. I think that the JsonPropertyOrder annotation is for when I want to specify my own custom order.

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To post to this group, send email to jackso...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages