There's a library class, the definition is:
class LibraryBean {
public String tag;
public Map<String, Object> attributes;
}
In my application code, I know every possible key for the attributes map, and the type of value of a certain key is fixed, for example, if the key is "location" then the value type is Location, if the key is "timestamp" then the value type is Long. Writing an ArrayList<LibraryBean> to a json string is simple, but how can I deserialize the json string so that the value recovers its type?
public void test(ArrayList<LibraryBean> sampleList) {
ObjectMapper mapper = new ObjectMapper();
String jsonString = mapper.writeAsString(sampleList);
List<LibraryBean> recovered = mapper.readValue(jsonString); // what should I do here?
// I'm sure sampleList.get(0).attributes.get("location") != null
AssertTrue(sampleList.get(0).attributes.get("location") instanceof Location);
}