-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
2.18Issues planned at 2.18 or laterIssues planned at 2.18 or laterlombokIssue (likely) related to use of LombokIssue (likely) related to use of Lombok
Description
Jackson 2.18.3 fails to deserialize classes with @Builder (Lombok) and ImmutableList (Guava) fields. This worked in Jackson 2.18.1 but breaks after upgrading to 2.18.3 (via Spring Boot 3.4.0 → 3.4.5).
Error
com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
Cannot construct instance of com.google.common.collect.ImmutableList
(no Creators, like default constructor, exist)
Code that fails
@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = PRIVATE)
class MimirAssertsRelabelRules {
private ImmutableList<MimirRelabelRuleGroup> asserts;
}
ObjectMapper mapper = new ObjectMapper()
.registerModule(new GuavaModule());
// This throws InvalidDefinitionException
mapper.readValue(json, MimirAssertsRelabelRules.class);Workaround that works
Add @JsonCreator to force constructor-based deserialization:
@Builder
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = PRIVATE)
class MimirAssertsRelabelRules {
private ImmutableList<MimirRelabelRuleGroup> asserts;
@JsonCreator
public static MimirAssertsRelabelRules fromJson(@JsonProperty("asserts") List<MimirRelabelRuleGroup> asserts) {
return new MimirAssertsRelabelRules(
asserts != null ? ImmutableList.copyOf(asserts) : ImmutableList.of()
);
}
}This works because it bypasses the builder pattern and uses constructor-based deserialization.
Question
Can anyone help explain why this changed between 2.18.1 and 2.18.3?
Metadata
Metadata
Assignees
Labels
2.18Issues planned at 2.18 or laterIssues planned at 2.18 or laterlombokIssue (likely) related to use of LombokIssue (likely) related to use of Lombok