I am trying to find an optimal way to deserialize dynamic fields that all contain the same value object structure:
"data": {
"lastUpdate": 1605299294253,
"tableData": [
{
"recordId": 1,
"isSelected": 1,
"myKey1": {
"valueRef": 72,
"value": "Some value"
},
"myKey2": {
"valueRef": 0,
"value": "123"
}
}
]
}
For the tableData JSON array, I have tried this approach without success:
import lombok.Data;
import java.util.Map;
@Data
public class TableRowDataVO {
private Integer recordId;
private Integer recordStatus;
private Map<String, TableRowDetailVO> columnData1;
private Map<String, TableRowDetailVO> columnData2;
}
This class is nested into another class to encompass the entire JSON body in data:
public class TabularDataDTO {
private Long lastUpdate;
private List<TableRowDataVO> tableData;
}
and each dynamic field holds the same Object of the following type:
public class TableRowDetailVO {
private Integer valueRef;
private String value;
}
There is also no guarantee that there are only 2 dynamic keys. It can be 0 to many dynamic keys that are in TableRowDataVO, but if there are limitations that require me to settle with 2, I can do that, but if 0 to many dynamic fields are possible, that would be great. I am trying to use the ObjectMapper with TypeReference as TabularDataVO but it throws an exception. What is the proper way to design my objects such that TabularDataVO can be deserialized by the mapper?