quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.57k stars 2.63k forks source link

Reflection free serializer doesn't take `JsonInclude.Include.NON_ABSENT` into account #43223

Open luneo7 opened 6 days ago

luneo7 commented 6 days ago

Describe the bug

When serializing something setting JsonInclude.Include.NON_ABSENT in an objectmapper customizer the reflection free serializer doesn't check the settings when serializing null values or absent (Java 8)

Expected behavior

Reflection free serializer takes the current object mapper serialization settings when serializing values

Actual behavior

Values get serialized as null.

How to Reproduce?

Get an Quarkus quickstart with Quarkus 3.14.3 set:

quarkus.rest.jackson.optimization.enable-reflection-free-serializers=true

Create an object mapper customizer:

@Singleton
public class RegisterObjectMapperCustomizer implements ObjectMapperCustomizer {

    @Override
    public void customize(ObjectMapper objectMapper) {
        objectMapper
                .enable(DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES)
                .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .setSerializationInclusion(JsonInclude.Include.NON_ABSENT);
    }
}

Create one endpoint that has a return type with Optional and set the optional to empty, instead of having the field omitted, it will be there with null value

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.14.3

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

luneo7 commented 5 days ago

/cc @mariofusco

quarkus-bot[bot] commented 5 days ago

/cc @gsmet (jackson), @mariofusco (jackson)