Skip to content

Duplicated field serialization using the generated reflection free Jackson serializers #44316

@mariofusco

Description

@mariofusco

Describe the bug

Enabling reflection-free serializers generates the following error in one specific scenario:

Suppressed: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No fallback setter/field defined for creator property 'is_enabled' (through reference chain: java.util.ArrayList[0]->com.dev.StateInfoDto["is_enabled"])
    at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67)
    <additional stack trace omitted for brevity>

The StateInfoDto is defined as a record class with Jackson annotations as follows:

@Builder(toBuilder = true)
@JsonIgnoreProperties(ignoreUnknown = true)
public record StateInfoDto (
    String name, @JsonProperty("is_enabled") boolean isEnabled) {}

The error does not occur when disabling the reflection-free serializers.

The error is actually caused by the fact that with that specific record the generated serializer mistakenly writes the field is_enabled twice producing the following json:

{"code":"AL","is_enabled":true,"name":"Alabama","is_enabled":true}

A reproducer of this issue is provided here https://github.com/iqnev/quarkus-json-reproducer

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

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

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/jacksonIssues related to Jackson (JSON library)kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions