Skip to content

[BUG] Missing properties using @Accessors(fluent = true) in Jackson 3.0.3 #4004

@giacgbj

Description

@giacgbj

The following behavior changed migrating from Jackson 2.20.1 to 3.0.3. I'm using Lombok 1.18.42 and I know it's not officially supported by Jackson.

Using @Accessors(fluent = true) causes missing properties.

Let's start with a working example.

I have this class which uses Lombok annotations:

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

@Data
public class Foo {
    private String a;
    private String b;

    @JsonCreator
    public Foo(@JsonProperty("a") final String a, @JsonProperty("b") final String b) {
        this.a = a;
        this.b = b;
    }
}
@Test
void testJacksonMigration() throws Exception {
    final Foo foo = new Foo("1", "2");

    final JsonMapper jsonMapper = JsonMapper.builder().build();
    final String json = jsonMapper.writeValueAsString(foo);
    System.out.println(json);
}

prints correctly {"a":"1","b":"2"}.

If I add to Foo class "@Accessors(fluent = true)" with Jackson 3 it doesn't work anymore, so:

[...]
import lombok.experimental.Accessors;

@Data
@Accessors(fluent = true)
public class Foo {
[...]

the test prints {}.

As a workaround, I added to each field a redundant @JsonProperty, but it works also with @JsonFormat, and probably any Jackson annotation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions