diff --git a/extensions/resteasy-reactive/rest-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/JacksonSerializerFactory.java b/extensions/resteasy-reactive/rest-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/JacksonSerializerFactory.java index 6ca5109cd4e21..457977f1f4064 100644 --- a/extensions/resteasy-reactive/rest-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/JacksonSerializerFactory.java +++ b/extensions/resteasy-reactive/rest-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/JacksonSerializerFactory.java @@ -190,13 +190,13 @@ protected boolean createSerializationMethod(ClassInfo classInfo, ClassCreator cl private boolean serializeObject(ClassInfo classInfo, ClassCreator classCreator, String beanClassName, MethodCreator serialize) { - Set serializedFields = new HashSet<>(); SerializationContext ctx = new SerializationContext(serialize, beanClassName); // jsonGenerator.writeStartObject(); MethodDescriptor writeStartObject = MethodDescriptor.ofMethod(JSON_GEN_CLASS_NAME, "writeStartObject", "void"); serialize.invokeVirtualMethod(writeStartObject, ctx.jsonGenerator); + Set serializedFields = new HashSet<>(); boolean valid = serializeObjectData(classInfo, classCreator, serialize, ctx, serializedFields); // jsonGenerator.writeEndObject(); @@ -222,7 +222,7 @@ private boolean serializeFields(ClassInfo classInfo, ClassCreator classCreator, SerializationContext ctx, Set serializedFields) { for (FieldInfo fieldInfo : classFields(classInfo)) { FieldSpecs fieldSpecs = fieldSpecsFromField(classInfo, fieldInfo); - if (fieldSpecs != null && serializedFields.add(fieldSpecs.fieldName)) { + if (fieldSpecs != null && serializedFields.add(fieldSpecs.jsonName)) { if (fieldSpecs.hasUnknownAnnotation()) { return false; } @@ -236,7 +236,7 @@ private boolean serializeMethods(ClassInfo classInfo, ClassCreator classCreator, SerializationContext ctx, Set serializedFields) { for (MethodInfo methodInfo : classMethods(classInfo)) { FieldSpecs fieldSpecs = fieldSpecsFromMethod(methodInfo); - if (fieldSpecs != null && serializedFields.add(fieldSpecs.fieldName)) { + if (fieldSpecs != null && serializedFields.add(fieldSpecs.jsonName)) { if (fieldSpecs.hasUnknownAnnotation()) { return false; } diff --git a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonResource.java b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonResource.java index 05f12b8e9ebf4..855c43625c09e 100644 --- a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonResource.java +++ b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonResource.java @@ -116,6 +116,13 @@ public Dog echoDog(Dog dog) { return dog; } + @POST + @Path("/record-echo") + @Consumes(MediaType.APPLICATION_JSON) + public StateRecord echoDog(StateRecord stateRecord) { + return stateRecord; + } + @EnableSecureSerialization @GET @Path("/abstract-cat") diff --git a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonTest.java b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonTest.java index 1c59ae89d210c..d2f22569f9a7a 100644 --- a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonTest.java +++ b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonTest.java @@ -6,6 +6,7 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.function.Supplier; @@ -35,7 +36,7 @@ public JavaArchive get() { AbstractPet.class, Dog.class, Cat.class, Veterinarian.class, AbstractNamedPet.class, AbstractUnsecuredPet.class, UnsecuredPet.class, SecuredPersonInterface.class, Frog.class, Pond.class, FrogBodyParts.class, FrogBodyParts.BodyPart.class, ContainerDTO.class, - NestedInterface.class) + NestedInterface.class, StateRecord.class) .addAsResource(new StringAsset("admin-expression=admin\n" + "user-expression=user\n" + "birth-date-roles=alice,bob\n"), "application.properties"); @@ -709,4 +710,27 @@ public void testEchoWithMissingPrimitive() { .body("veterinarian.name", Matchers.is("Dolittle")) .body("veterinarian.title", Matchers.nullValue()); } + + @Test + public void testRecordEcho() { + String response = RestAssured + .with() + .body("{\"code\":\"AL\",\"is_enabled\":true,\"name\":\"Alabama\"}") + .contentType("application/json; charset=utf-8") + .post("/simple/record-echo") + .then() + .statusCode(200) + .contentType("application/json") + .body("name", Matchers.is("Alabama")) + .body("code", Matchers.is("AL")) + .body("is_enabled", Matchers.is(true)) + .extract() + .asString(); + + int first = response.indexOf("is_enabled"); + int last = response.lastIndexOf("is_enabled"); + // assert that the "is_enabled" field is present only once in the response + assertTrue(first >= 0); + assertEquals(first, last); + } } diff --git a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonWithReflectionFreeSerializersTest.java b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonWithReflectionFreeSerializersTest.java index 0254e48598fe8..65dec05aa59a4 100644 --- a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonWithReflectionFreeSerializersTest.java +++ b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/SimpleJsonWithReflectionFreeSerializersTest.java @@ -25,7 +25,7 @@ public JavaArchive get() { AbstractPet.class, Dog.class, Cat.class, Veterinarian.class, AbstractNamedPet.class, AbstractUnsecuredPet.class, UnsecuredPet.class, SecuredPersonInterface.class, Frog.class, Pond.class, FrogBodyParts.class, FrogBodyParts.BodyPart.class, ContainerDTO.class, - NestedInterface.class) + NestedInterface.class, StateRecord.class) .addAsResource(new StringAsset("admin-expression=admin\n" + "user-expression=user\n" + "birth-date-roles=alice,bob\n" + diff --git a/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/StateRecord.java b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/StateRecord.java new file mode 100644 index 0000000000000..1e7aed0af9943 --- /dev/null +++ b/extensions/resteasy-reactive/rest-jackson/deployment/src/test/java/io/quarkus/resteasy/reactive/jackson/deployment/test/StateRecord.java @@ -0,0 +1,8 @@ +package io.quarkus.resteasy.reactive.jackson.deployment.test; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonIgnoreProperties(ignoreUnknown = true) +public record StateRecord(String name, String code, @JsonProperty("is_enabled") boolean isEnabled) { +} \ No newline at end of file