-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could you provide the "ObjectMapper.treeToValue(TreeNode, TypeReference)" method? #4046
Comments
This seems like something that could be an easy PR for someone looking for things to tackle; will label as such. |
ObjectMapper mapper = new ObjectMapper();
ArrayNode node = mapper.createArrayNode();
node.add("123").add("456");
try {
List<String> list = mapper.convertValue(node, new TypeReference<List<String>>() {
});
} catch(Exception e) {
e.printStackTrace();
} |
Are you suggesting method name changed to |
No. 'convertValue' is an existing method. When fromValue is 'JsonNode', it should be equivalent to 'treeToValue'. But I'm not sure if there is a performance difference between them at the moment, as 'convertValue' seems to need to be serialized first. When fromValue is 'JsonNode', can this step be omitted? |
I think not and there is a reason for it. I don't remember in which issue or PR, but has been a discussion around it. |
Actually serialization part can in fact be avoided because it is possible to create |
Fixed via #4056, closing. Will be in 2.16.0 |
Is your feature request related to a problem? Please describe.
The situation now is that without this overloaded method, I need to write extra code to achieve the result I want.
Describe the solution you'd like
Could you provide this method to simplify my code?
Like the code below.
Usage example
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: