-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels