'Ignore enclosing braces with JSON parser while serializing object in Java
I have the following classes:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class User {
private String id;
private List<Reference> references;
.....
}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Reference {
@JacksonXmlProperty(isAttribute = true)
private String ref;
public Reference(final String ref) {
this.ref = ref;
}
public Reference() { }
public String getRef() {
return ref;
}
}
When serializing to XML the format is as expected, but when I try to serialize to JSON I get the following
"users" : [
{
"references" : [
{
"ref": "referenceID"
}
]
}
]
And I need it to be:
"users" : [
{
"references" : [
"referenceID"
]
}
]
the braces enclosing the reference list I need it to be ignored without the attribute name
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
