Given the JSON string I need to convert it to my POJO named TransactionInfo
JSON String
{
"transactionId": "EFODKKXHE003",
"isSettled": false,
"transactionProperties": [
{
"key1": "Value1"
},
{
"key2": "Value2"
},
{
"key3": "Value3"
}
]
}
POJO
class TransactionInfo {
String transactionId;
Boolean isSettled;
Map<String,String> transactionProperties;
}
Additional Note (From comment)
After the deserialization, I want to access different keys in the transactionProperties map. If it's converted into a List<Map<String,String>> then it becomes complex. FYI, the keys are guaranteed to be unique so in the end, I want one single flat map. Another point, I don't need to serialize TransactionInfo back to JSON.
What I tried
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.readValue(jsonString, TransactionInfo.class);
But I am getting an exception like below:
Cannot deserialize value of type java.util.LinkedHashMap<java.lang.String,java.lang.Object> from Array value (token JsonToken.START_ARRAY)
Can anyone guide me on how to do that properly? Any help is much appreciated.
Edit
I have already gone through the following post(s) but none of them seems to match my use case
[...]represents list/array of elements. So instead ofMap<String,String> transactionProperties;you wantList<Map<String,String>> transactionProperties;TransactionInfoback to JSON. Should that flat-map be split back to list of objects with single keys or to single object with many unique keys. If it is split back to array of objects then will their order matter?