Skip to content
Advertisement

deserialization of a json array to a list and retaining the array order from json within list

I have the following json that is mapped to a POJO using Jackson mapper. How do I retain the order of array columns from json during deserialization ? What annotation should I use ?

JSON:

JavaScript

}

POJO:

JavaScript

}

  • Expected getColumnNames(): {“FirstName”,”LastName”,”UserName”}
  • Actual getColumnNames(): {“UserName”,”FirstName”,”LastName”}

I am new to Jackson mapping so any help is appreciated.

Advertisement

Answer

Jackson mapper fill the ArrayList maintaining the order of JSON. If you want a different order you can use the annotation @JsonPropertyOrder.

(https://fasterxml.github.io/jackson-annotations/javadoc/2.8/com/fasterxml/jackson/annotation/JsonPropertyOrder.html)

Advertisement