1

When Serializing a pojo with JAXB-JSON it can wrap the root element name around the object data. For example:

@XmlRootElement(name="worker")
public class Employee {
    private int id;
    private String name; //...
}

Can give JSON such as :

{ "worker" : { "id" : 1, "name" : "Ashraf" } }

What are some ways to achieve this using Jackson JSON serialization?

Gonen I
  • 5,576
  • 1
  • 29
  • 60

1 Answers1

1

I found an answer. For Jackson 2.2 and above

You need to configure your DTO class as follows:

@JsonRootName(value = "worker")

You need to configure your jackson object mapper as follows:

mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);

For older versions, see here: Jackson JSON Deserialization with Root Element

Gonen I
  • 5,576
  • 1
  • 29
  • 60