I have following json having an array with field name page_names which can contain either string or another object. Is there any way to convert it into java object using jackson?? I have two classes: PageStructure corresponding to whole object and PageInfo for storing object like { "name": "Candidate Information", "section":2 }.
{
"url": "http://example.com",
"is_auth_required": false,
"page_names": [
"Hello",
{
"name": "Candidate Information",
"section":2
},
{
"page_name": "Resume and Cover Letter",
"section":3
}
]
}
I can convert using following code but then I have to recognize whether object has string or PageInfo explicitly.
@JsonIgnoreProperties(ignoreUnknown = true)
public class PageStructure {
@JsonProperty("url")
String Url;
@JsonProperty("is_auth_required")
boolean isAuthRequired = true;
@JsonProperty("page_names")
List<Object> PageNames;
//GETTERS AND SETTERS
}
Is there any other approach where It is possible to give page_names is either String or PageInfo object??
setPageNames, one that takes a string and one that takes the object