2

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.