I have a JSON string
{
"type": "com.example.model.Person",
"data": {
"firstName": "Bob",
...
}
}
That is represented by the following class.
public class Container<T> {
private String type;
private T data;
// Getters and Setters
}
(I've even tried just removing the generic type and replacing it with Object
.)
I have tried the following:
new ObjectMapper().readValue(json, Class.forName(canonical))
new ObjectMapper().readValue(json, TypeFactory.defaultInstance().constructFromCanonical(canonical))
I need to be able to deserialize the JSON string into a Container<T>
instance with only the given canonical type string. How can this be done?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.