Skip to content

Commit 2fe27df

Browse files
authored
Merge pull request #44309 from mariofusco/q44300
Avoid deserializing null nodes in reflection free Jackson serialization
2 parents 6e39316 + 33066b8 commit 2fe27df

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

extensions/resteasy-reactive/rest-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/JacksonDeserializerFactory.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
* Map.Entry entry = (Map.iterator) var3.next();
157157
* String field = (String) entry.getKey();
158158
* JsonNode jsonNode = (JsonNode) entry.getValue();
159+
* if (jsonNode.isNull()) {
160+
* continue;
161+
* }
159162
* switch (field) {
160163
* case "content":
161164
* dataItem.setContent(context.readTreeAsValue(jsonNode, this.valueTypes[0]));
@@ -240,10 +243,13 @@ private boolean deserializeObject(ClassInfo classInfo, ResultHandle objHandle, C
240243
.invokeInterfaceMethod(ofMethod(Map.Entry.class, "getKey", Object.class), mapEntry);
241244
ResultHandle fieldValue = loopCreator.checkCast(loopCreator
242245
.invokeInterfaceMethod(ofMethod(Map.Entry.class, "getValue", Object.class), mapEntry), JsonNode.class);
243-
Switch.StringSwitch strSwitch = loopCreator.stringSwitch(fieldName);
246+
247+
loopCreator.ifTrue(loopCreator.invokeVirtualMethod(ofMethod(JsonNode.class, "isNull", boolean.class), fieldValue))
248+
.trueBranch().continueScope(loopCreator);
244249

245250
Set<String> deserializedFields = new HashSet<>();
246251
ResultHandle deserializationContext = deserialize.getMethodParam(1);
252+
Switch.StringSwitch strSwitch = loopCreator.stringSwitch(fieldName);
247253
return deserializeFields(classCreator, classInfo, deserializationContext, objHandle, fieldValue, deserializedFields,
248254
strSwitch, parseTypeParameters(classInfo, classCreator));
249255
}

extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,24 @@ public void testEcho() {
675675
.body("veterinarian.title", Matchers.nullValue());
676676
}
677677

678+
@Test
679+
public void testEchoWithNullString() {
680+
RestAssured
681+
.with()
682+
.body("{\"publicName\":null,\"veterinarian\":{\"name\":\"Dolittle\"},\"age\":5,\"vaccinated\":true}")
683+
.contentType("application/json; charset=utf-8")
684+
.post("/simple/dog-echo")
685+
.then()
686+
.statusCode(200)
687+
.contentType("application/json")
688+
.body("publicName", Matchers.nullValue())
689+
.body("privateName", Matchers.nullValue())
690+
.body("age", Matchers.is(5))
691+
.body("vaccinated", Matchers.is(true))
692+
.body("veterinarian.name", Matchers.is("Dolittle"))
693+
.body("veterinarian.title", Matchers.nullValue());
694+
}
695+
678696
@Test
679697
public void testEchoWithMissingPrimitive() {
680698
RestAssured

0 commit comments

Comments
 (0)