You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Try putting @JsonRootName("info") on static class Info. Annotations that have names starting with JacksonXml only affect XML (eg @JacksonXmlProperty(localName = "info")) and do not affect JSON.
Try putting @JsonRootName("info") on static class Info. Annotations that have names starting with JacksonXml only affect XML (eg @JacksonXmlProperty(localName = "info")) and do not affect JSON.
Adding @JsonRootName on Info like below, i've tried but it didn't work.
@JsonRootName("info")
static class Info {
public Info(String name, String sex) {
super();
this.name = name;
this.sex = sex;
}
private String name;
private String sex;
...
setters and getters
...
}
Behavior of JSON and XML differ because they are conceptually different data formats: they cannot be handled identically.
I don't just mean curly braces vs angle brackets, but rather that structural components are different.
Because of this certain wrapping that XML typically requires (since it lacks native Array type, elements are used for Arrays and Objects) are not added in JSON.
So I don't think there is anything to work on here.
If you have specific types of JSON or XML structures you want, please file issue at appropriate repo (for XML, this one, for JSON jackson-databind). But general "why isn't JSON output like XML" (and vice versa) questions are not useful.
Trying to serialize POJOs containing arrays or collections.
Noticed that arrays or collections are handled correctly in XML when serializing:
But in JSON:
And not sure that we should get:
We use Jackson Dataformat XML 2.15.2
codes:
The text was updated successfully, but these errors were encountered: