8
8
import com .fasterxml .jackson .databind .type .LogicalType ;
9
9
10
10
import javax .json .Json ;
11
- import javax .json .JsonArray ;
12
11
import javax .json .JsonPatch ;
13
- import javax .json .JsonValue ;
14
- import javax .json .JsonValue .ValueType ;
15
12
import java .io .IOException ;
16
13
17
14
public class JsonPatchDeserializer extends StdDeserializer <JsonPatch > {
@@ -31,18 +28,9 @@ public LogicalType logicalType() {
31
28
@ Override
32
29
public JsonPatch deserialize (JsonParser p , DeserializationContext ctxt ) throws IOException {
33
30
if (p .currentToken () != JsonToken .START_ARRAY ) {
34
- throw getException (p , p .getText ());
31
+ throw InvalidFormatException .from (p , "JSON patch has to be an array of objects" , p .getText (),
32
+ handledType ());
35
33
}
36
- final JsonArray patch = jsonValueDeser ._deserializeArray (p , ctxt );
37
- for (final JsonValue element : patch .getValuesAs (JsonValue .class )) {
38
- if (element .getValueType () != ValueType .OBJECT ) {
39
- throw getException (p , element .toString ());
40
- }
41
- }
42
- return Json .createPatch (patch );
43
- }
44
-
45
- private InvalidFormatException getException (final JsonParser p , final String value ) {
46
- return InvalidFormatException .from (p , "JSON patch has to be an array of objects" , value , handledType ());
34
+ return Json .createPatch (jsonValueDeser ._deserializeArray (p , ctxt ));
47
35
}
48
36
}
0 commit comments