-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Milestone
Description
(note: inspired by #3000)
A very common use pattern for deserializers is to read content as a tree (JsonNode
) and then extract properties, either simple scalar values (Strings, numbers, boolean), or to further bind as POJOs via delegation.
But while there is a way to achieve that, the "proper" way is somewhat complicated, by:
- Constructing
JsonParser
out ofJsonNode
(methodtraverse()
) - Either locating deserializer to use (
find[Non]ContextualValueDeserializer()
) and calling it; or using short-cut ofreadValue()
(or readPropertyValue()`)
Because of this, many users instead use construct like:
JsonNode tree = ctxt.readTree(p);
MyPojo value = ctxt.getCodec(). treeToValue(tree.get("pojo"), MyPojo.class);
which has been available since Jackson 2.0, but has some issue regarding not retaining current deserialization context and things like Attributes set.
So it would make sense to add a convenience method that does what is intended starting with existing JsonNode
(first checking for null
and "missing node"?), locating deserializer & reading.
Naming TBD, could be:
DeserializationContext.treeToValue(JsonNode, Class<?> targetType); // and other method with `JavaType`
Metadata
Metadata
Assignees
Labels
No labels