Skip to content
Advertisement

Jackson JSON do not wrap attributes of nested object

I’ve got following classes:

JavaScript

When I serialize Container class using Jackson I get

JavaScript

But I need the result to be:

JavaScript

Is it possible (without adding Container.getDataId() method)? If so, how to do it?


update

I’ve tried to create custom JsonSerializer<Data> but the result was same as before

JavaScript

I’ve also tried to add @JsonSerialize annotation above Data class, then above getter in Container class. As I mentioned before without any success. My serializer is used, logger logs message.


update 2

When I remove writeStartObject() and writeEndObject() then no JSON is returnesd, only HTTP Status 500 error and no exception is thrown except of what I found in debug output.

JavaScript

Advertisement

Answer

Jackson 1.9 has introduced JsonUnwrapped annotation which does what you are looking for.

Advertisement