I'm trying to get some Json from an API and parse them into some POJO's to work with them but i have this case where i can get for a key a simple String or an arrayList of Strings.
The Json looks like this :
{
"offerDisplayCategoryMapping": [
{
"offerKey": "EUICC_BASE_ACTIVATION_V01",
"categoriesKeys": {
"categoryKey": "Included"
}
},
{
"offerKey": "EUICC_BASE_ACTIVATION_V02",
"categoriesKeys": {
"categoryKey": "Included"
}
},
{
"offerKey": "EUICC_BASE_ACTIVATION_V03",
"categoriesKeys": {
"categoryKey": [
"Option",
"Included"
]
}
}]
}
I'm using Spring Rest to get the result from the API. I created a POJO that represents categoriesKeys
with a List<String>
that defines categoryKey
and in my RestTemplate
I defined an ObjectMapper
where i enabled DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY
for the case of simple strings but this doesn't work!!
Any suggestions?
In addition to global configuration already mentioned, it is also possible to support this on individual properties: