Hi guys I have problem in Java. The problem is around parsing JSON with Jackson as I was instructed. My JSON is parsed well, that's not the problem. The problem lies in that I have multiple JSON items in one JSON. I've parsed it like this:
ObjectMapper objectMapper = new ObjectMapper();
try {
List<Unit> unitList = objectMapper.readValue(json,List.class);
System.out.println("UnitSize " + String.valueOf(unitList.size()));
System.out.println(unitList.get(0).getUnitEmail());
} catch (IOException e) {
e.printStackTrace();
}
and at UnitSize it'll tell me that I have precisely 5 objects of Unit type, which is okay, but when I want to get something out of the List it says me this:
Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.reddatura.API.HTTPRequest$Unit
I've googled it, but nothing relevant. What should be the problem
EDIT:
here is my class snippet:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Unit
{
@JsonProperty("unitid")
int unitId;
@JsonProperty("unitname")
String unitName;
@JsonProperty("unitlogo")
String unitLogo;
@JsonProperty("unitaddress")
String unitAddr;
//other fields, getters setters
@JsonCreator
public Unit()
{
}
}
I want to parse into this model
unitList.get(0)in the Debug environment. See if it containsUnitorLinkedHashMap