The class I'm serializing:
public class LogsDTO {
/** The logs. */
private List<LogDTO> logs;
/** Meta data. */
private Meta meta = new Meta();
// more
}
And the generated JSON:
{"LogsDTO":{"logs":[{"id":11,"archived":false}],"meta":{"totalPages":0}}}
I'd like my JSON to look like:
{"logs":[{"id":11,"archived":false}],"meta":{"totalPages":0}}
Is there a way to annotate so that this happens?
Thanks
@JsonRootName
: class annotation used to indicate name of "wrapper" entry used for root value, if root-wrapping is enabled.
Says in jackson docs : https://github.com/FasterXML/jackson-annotations/wiki/Jackson-Annotations
Related Jira Task: http://jira.codehaus.org/browse/JACKSON-630 1.9 and above versions supports it.
When investigate the source code of @JsonRootName,
They commented alwaysWrap method.
/* * Optional marker property that can be defined as
true
to force * wrapping of root element, regardless of whether globally * "root wrapping" is enabled or not. ** Note that value of
false
is taken to mean "use defaults", * and will not block use of wrapper if use is indicated by global features. * * @since 2.4 public boolean alwaysWrap() default false; */
They have a plan to activate it on v2.5
As of 2.4, one missing feature is property "alwaysWrap", which is hoped * to be added in 2.5, and would be used to force root name wrapping * for individual types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With