I have a list of JSON urls in the following format:
{
"level": 1,
"secondLevel": {
"level": 2,
"thirdLevel": [
{
"level": 3,
"fourthLevel": {
"level": 4,
"fifthLevel": [
{
"type": "URLS",
"listOfimageURLs": [
{
"urlNo": "Num1",
"data": "num1Data"
},
{
"urlNo": "Num2",
"data": "num2Data"
},
{
"urlNo": "Num3",
"data": "num3Data"
}
]
}
]
}
}
]
}
}
Initially I had something like this, gave me a List of Urls with everything in the List.
@Data
@NoArgsConstructor
public class URLDetail {
private String type;
private List<Urls> urlData;
}
Now I have the following Java POJO I'm trying to deserialise to, with the value num2Data
set in the field urlData
@Data
@NoArgsConstructor
public class URLDetail {
private String type;
private String urlData;
}
I'm trying to figure out how I can conditionally loop through the JSON list - url and for any urlNo equal to "Num2" deserialise the associated "data" field value (in this case "num2Data") to the URLDetail POJO field urlData?
I have the usual
mapper.readValue(json, URLDetail.class);
If I remove urlData the type
field is correctly set, but completely un-sure about applying logic to parse the urls list in JSON.
Do I need to create some kind of custom deserialiser?