I have following Json and want to map this json as java pojo using spring webclient mono response. in this json keys data-1 and en are not constants and keep changing. for example it could be data-2 and fr or data-3 and it.
{
"data": {
"attributes": {
"data-1": {
"en": [
{
"id": 1,
"code": "GI",
"order": 10
},
{
"id": 2,
"code": "TH",
"order": 10
}
]
}
}
}
}
DTO structure :
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ListData {
private Map<String, Attributes> data;
}
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Attributes {
private Map<String, Map<String, MyList>> attributes;
}
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MyList {
private List<Entry> entryList;
}
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Entry {
private String id;
private String code;
private String order;
}
here is webclient that deserialize json.
return WebClient.create("test.com")
.get()
.uri(getTestUri())
.header(HttpHeaders.ACCEPT, Constants.ACCEPT_TYPE)
.retrieve()
.bodyToMono(ListData.class)
.block();
Following is the error :
org.springframework.core.codec.CodecException: Type definition error: [simple type, class com.test.ListAttributes]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.test.ListAttributes` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
could someone help me on this, how can it be fixed.