I have a json which is something like following:
[{"type":"chair", "color":"red", "owners":["A","B"]}, {"type":"vase", "shape":"oval", "owners":["B", "C"]}]
As seen, both entries are different. So I need to deserialize this json and instantiate 2 objects Chair and Vase. The owners above should be List of enum in the appropriate object. The json can have many other different entries like that and in any order. So I am doing this:
List<Map<String, Object>> things = objectMapper.readValue(json,
objectMapper.getTypeFactory().constructCollectionType(List.class, Map.class));
things is a list of maps and each map will correspond to one thing. I iterate over the list and from each map check 'type' and instantiate the appropriate object. Eg:
if map.get("type") == "chair" then new Chair(map.get("color"), map.get("owners"));
Now I have an enum OWNERS. So I do this:
List<OWNERS> owners = (ArrayList<OWNERS>) map.get("owners");
I do get the list properly. But when I verify like this:
assertEquals(OWNERS.A, owners.get(0));
I get error: 'expected java.lang.OWNERS("A") but got java.lang.String("A")'
As you can see type of owners is List. What am I missing? Am I parsing the wrong way?