1111import com .fasterxml .jackson .core .JsonGenerator ;
1212import com .fasterxml .jackson .core .JsonParser ;
1313import com .fasterxml .jackson .core .TreeNode ;
14- import com .fasterxml .jackson .databind .*;
15- import com .fasterxml .jackson .databind .node .ArrayNode ;
16- import com .fasterxml .jackson .databind .node .NumericNode ;
17- import com .fasterxml .jackson .databind .node .ObjectNode ;
18- import com .fasterxml .jackson .databind .node .TextNode ;
14+ import com .fasterxml .jackson .databind .DeserializationContext ;
15+ import com .fasterxml .jackson .databind .JsonDeserializer ;
16+ import com .fasterxml .jackson .databind .JsonNode ;
17+ import com .fasterxml .jackson .databind .node .*;
1918
2019import java .io .ByteArrayOutputStream ;
2120import java .io .IOException ;
2625
2726public final class InternalDeserializers {
2827
28+ private static <T > T readTreeAsValue (JsonParser p , DeserializationContext ctxt , JsonNode n , Class <T > targetType ) throws IOException {
29+ try (TreeTraversingParser t = new TreeTraversingParser (n , p .getCodec ())) {
30+ t .nextToken ();
31+ return ctxt .readValue (t , targetType );
32+ }
33+ }
34+
2935 public static class CollectionLinksDeserializer extends JsonDeserializer <Collection <CollectionLink >> {
3036
3137 @ Override
@@ -37,7 +43,7 @@ public Collection<CollectionLink> deserialize(JsonParser p, DeserializationConte
3743 Map .Entry <String , JsonNode > e = it .next ();
3844 ObjectNode v = (ObjectNode ) e .getValue ();
3945 v .put ("name" , e .getKey ());
40- out .add (ctxt . readTreeAsValue (v , CollectionLink .class ));
46+ out .add (readTreeAsValue (p , ctxt , v , CollectionLink .class ));
4147 }
4248 return out ;
4349 }
@@ -54,7 +60,7 @@ public FieldLink[] deserialize(JsonParser p, DeserializationContext ctxt) throws
5460 Map .Entry <String , JsonNode > e = it .next ();
5561 ObjectNode v = (ObjectNode ) e .getValue ();
5662 v .put ("name" , e .getKey ());
57- out .add (ctxt . readTreeAsValue (v , FieldLink .class ));
63+ out .add (readTreeAsValue (p , ctxt , v , FieldLink .class ));
5864 }
5965 return out .toArray (new FieldLink [0 ]);
6066 }
@@ -126,7 +132,7 @@ public Response deserialize(final JsonParser p, final DeserializationContext ctx
126132 response .setType (it .next ().intValue ());
127133 response .setResponseCode (it .next ().intValue ());
128134 if (it .hasNext ()) {
129- response .setMeta (ctxt . readTreeAsValue (it .next (), Map .class ));
135+ response .setMeta (readTreeAsValue (p , ctxt , it .next (), Map .class ));
130136 }
131137 return response ;
132138 }
0 commit comments