20
20
package com .gravity9 .jsonpatch .mergepatch ;
21
21
22
22
import com .fasterxml .jackson .core .JsonParser ;
23
- import com .fasterxml .jackson .core .JsonProcessingException ;
24
- import com .fasterxml .jackson .core .ObjectCodec ;
25
23
import com .fasterxml .jackson .databind .DeserializationContext ;
26
24
import com .fasterxml .jackson .databind .JsonDeserializer ;
27
25
import com .fasterxml .jackson .databind .JsonNode ;
26
+ import com .fasterxml .jackson .databind .ObjectMapper ;
28
27
import com .fasterxml .jackson .databind .node .NullNode ;
29
- import com .github .fge .jackson .JacksonUtils ;
30
28
import java .io .IOException ;
31
29
import java .util .HashMap ;
32
30
import java .util .HashSet ;
35
33
import java .util .Set ;
36
34
37
35
final class JsonMergePatchDeserializer extends JsonDeserializer <JsonMergePatch > {
38
- /*
39
- * FIXME! UGLY! HACK!
40
- *
41
- * We MUST have an ObjectCodec ready so that the parser in .deserialize()
42
- * can actually do something useful -- for instance, deserializing even a
43
- * JsonNode.
44
- *
45
- * Jackson does not do this automatically; I don't know why...
46
- */
47
- private static final ObjectCodec CODEC = JacksonUtils .newMapper ();
48
36
49
37
@ Override
50
38
public JsonMergePatch deserialize (final JsonParser jp ,
51
- final DeserializationContext ctxt )
52
- throws IOException , JsonProcessingException {
53
- // FIXME: see comment above
54
- jp .setCodec (CODEC );
39
+ final DeserializationContext ctxt ) throws IOException {
40
+ ObjectMapper mapper = new ObjectMapper ().setConfig (ctxt .getConfig ());
41
+ jp .setCodec (mapper );
55
42
final JsonNode node = jp .readValueAsTree ();
56
43
57
44
/*
58
45
* Not an object: the simple case
59
46
*/
60
- if (!node .isObject ())
47
+ if (!node .isObject ()) {
61
48
return new NonObjectMergePatch (node );
49
+ }
62
50
63
51
/*
64
52
* The complicated case...
@@ -67,8 +55,8 @@ public JsonMergePatch deserialize(final JsonParser jp,
67
55
* members.
68
56
*/
69
57
70
- final Set <String > removedMembers = new HashSet <String >();
71
- final Map <String , JsonMergePatch > modifiedMembers = new HashMap <String , JsonMergePatch >();
58
+ final Set <String > removedMembers = new HashSet <>();
59
+ final Map <String , JsonMergePatch > modifiedMembers = new HashMap <>();
72
60
final Iterator <Map .Entry <String , JsonNode >> iterator = node .fields ();
73
61
74
62
Map .Entry <String , JsonNode > entry ;
0 commit comments