Skip to content

Commit 035f5b8

Browse files
patveckcowtowncoder
authored andcommitted
Do not check elements of the array
1 parent 58d8893 commit 035f5b8

File tree

2 files changed

+3
-30
lines changed

2 files changed

+3
-30
lines changed

jsr-353/src/main/java/com/fasterxml/jackson/datatype/jsr353/JsonPatchDeserializer.java

+3-15
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import com.fasterxml.jackson.databind.type.LogicalType;
99

1010
import javax.json.Json;
11-
import javax.json.JsonArray;
1211
import javax.json.JsonPatch;
13-
import javax.json.JsonValue;
14-
import javax.json.JsonValue.ValueType;
1512
import java.io.IOException;
1613

1714
public class JsonPatchDeserializer extends StdDeserializer<JsonPatch> {
@@ -31,18 +28,9 @@ public LogicalType logicalType() {
3128
@Override
3229
public JsonPatch deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
3330
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());
3533
}
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));
4735
}
4836
}

jsr-353/src/test/java/com/fasterxml/jackson/datatype/jsr353/JsonPatchDeserializationTest.java

-15
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,6 @@ public void testArrayOfObjectsDeserializationAndPatching() throws Exception {
5454
assertThat(patchedPerson, is(new Person("Json", "Smith")));
5555
}
5656

57-
public void testArrayWithOScalarDeserializationAndPatching() {
58-
final String json = "[" +
59-
"{" +
60-
"\"op\":\"replace\"," +
61-
"\"path\":\"/name\"," +
62-
"\"value\":\"Json\"" +
63-
"}," +
64-
"\"Jackson\"" +
65-
"]";
66-
67-
final InvalidFormatException ex = assertThrows(InvalidFormatException.class,
68-
() -> MAPPER.readValue(json, JsonPatch.class));
69-
assertThat(ex.getMessage(), containsString(EXPECTED_MESSAGE));
70-
}
71-
7257
public void testObjectDeserializationAndPatching() {
7358
final String json = "{" +
7459
"\"op\":\"replace\"," +

0 commit comments

Comments
 (0)