2525import com .fasterxml .jackson .core .JsonGenerationException ;
2626import com .fasterxml .jackson .core .JsonParser ;
2727import com .fasterxml .jackson .core .JsonProcessingException ;
28+ import com .fasterxml .jackson .core .ObjectCodec ;
2829import com .fasterxml .jackson .databind .DeserializationContext ;
2930import com .fasterxml .jackson .databind .JsonNode ;
3031import com .fasterxml .jackson .databind .deser .std .StdDeserializer ;
@@ -43,46 +44,51 @@ protected ExtensionsDeserializer() {
4344 public Map deserialize (JsonParser parser , DeserializationContext deserializationContext )
4445 throws IOException , JsonProcessingException {
4546
46- JsonNode node = parser .getCodec ().readTree (parser );
47- Iterator <JsonNode > iter = node .iterator ();
48-
4947 Map <Object , Object > map = new HashMap <>();
5048
51- while (iter .hasNext ()) {
52- JsonNode en = iter .next ();
53- try {
54- Class <?> clazz = Class .forName (en .get ("class" ).asText ());
55- String key = en .has ("key" ) ? en .get ("key" ).asText () : null ;
56- JsonNode nodeContent = en .get ("content" );
49+ ObjectCodec codec = parser .getCodec ();
50+ if (codec != null ) {
51+ JsonNode node = parser .getCodec ().readTree (parser );
52+ Iterator <JsonNode > iter = node .iterator ();
53+
54+ while (iter .hasNext ()) {
55+ JsonNode en = iter .next ();
56+ try {
57+ Class <?> clazz = Class .forName (en .get ("class" ).asText ());
58+ String key = en .has ("key" ) ? en .get ("key" ).asText () : null ;
59+ JsonNode nodeContent = en .get ("content" );
5760
58- Object mapKey ;
59- Object content ;
61+ Object mapKey ;
62+ Object content ;
6063
61- if (nodeContent .isArray ()) {
62- content = new LinkedList <>();
63- for (JsonNode aNodeContent : nodeContent ) {
64- JsonParser panc = aNodeContent .traverse ();
65- panc .nextToken ();
66- Object co = deserializationContext .readValue (panc , clazz );
67- ((List ) content ).add (co );
64+ if (nodeContent .isArray ()) {
65+ content = new LinkedList <>();
66+ for (JsonNode aNodeContent : nodeContent ) {
67+ JsonParser panc = aNodeContent .traverse ();
68+ panc .nextToken ();
69+ Object co = deserializationContext .readValue (panc , clazz );
70+ ((List ) content ).add (co );
71+ }
72+ } else {
73+ JsonParser cjp = nodeContent .traverse ();
74+ cjp .nextToken ();
75+ content = deserializationContext .readValue (cjp , clazz );
6876 }
69- } else {
70- JsonParser cjp = nodeContent .traverse ();
71- cjp .nextToken ();
72- content = deserializationContext .readValue (cjp , clazz );
73- }
7477
75- if (key == null ) {
76- mapKey = clazz ;
77- } else {
78- mapKey = new Extensible .Key (clazz , key );
79- }
78+ if (key == null ) {
79+ mapKey = clazz ;
80+ } else {
81+ mapKey = new Extensible .Key (clazz , key );
82+ }
8083
81- map .put (mapKey , content );
84+ map .put (mapKey , content );
8285
83- } catch (ClassNotFoundException e ) {
84- throw new JsonGenerationException (e );
86+ } catch (ClassNotFoundException e ) {
87+ throw new JsonGenerationException (e );
88+ }
8589 }
90+ } else {
91+ parser .nextToken ();
8692 }
8793
8894 return map ;
0 commit comments