-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
to-evaluateIssue that has been received but not yet evaluatedIssue that has been received but not yet evaluated
Description
Is your feature request related to a problem? Please describe.
Currently to deserialize object in ObjectMapper we use below syntax -
ObjectMapper m = new ObjectMapper();
final String JSON = "{ \"x\" : 3 }";
Bean bean = m.readValue(JSON, Bean.class);
Can ObjectMapper automatically detect the class to be deserialized based on the return type?
This is already implemented in Mockito mockito/mockito#2779
Describe the solution you'd like
Below method can be added in ObjectMapper class to detect class automatically.
public <T> T readValue(String content, T... reified) throws JsonProcessingException {
if (reified.length > 0) {
throw new IllegalArgumentException("Please don't pass any values here. Java will detect class automatically.");
}
return readValue(content, _typeFactory.constructType(getClassOf(reified)));
}
Usage example
ObjectMapper m = new ObjectMapper();
final String JSON = "{ \"x\" : 3 }";
Bean bean = m.readValue(JSON);
Additional context
No response
JooHyukKimJooHyukKim
Metadata
Metadata
Assignees
Labels
to-evaluateIssue that has been received but not yet evaluatedIssue that has been received but not yet evaluated