Skip to content

Could you provide the "ObjectMapper.treeToValue(TreeNode, TypeReference)" method? #4046

Closed
@fantasy0v0

Description

@fantasy0v0

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.

ObjectMapper mapper = new ObjectMapper();
ArrayNode node = mapper.createArrayNode();
node.add("123").add("456");
JavaType javaType = mapper.constructType(new TypeReference<List<String>>() {});
try {
    mapper.treeToValue(node, javaType);
} catch(Exception e) {
    e.printStackTrace();
}

Describe the solution you'd like

Could you provide this method to simplify my code?

Like the code below.

ObjectMapper mapper = new ObjectMapper();
ArrayNode node = mapper.createArrayNode();
node.add("123").add("456");
try {
    mapper.treeToValue(node, new TypeReference<List<String>>() {});
} catch(Exception e) {
    e.printStackTrace();
}

Usage example

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssue that seems easy to resolve and is likely a good candidate for contributors new to project

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions