You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating with strictBuilder = true, there is no @JsonProperty("lines") annotation on any of the
methods related to collections, which makes Jackson fail with an UnrecognizedPropertyException for the collections.
@Value.Immutable
@Value.Style(overshadowImplementation = true,
jdkOnly = true, strictBuilder = true)
@JsonDeserialize(builder = OrderLine.Builder.class)
public interface OrderLine {
@JsonProperty("id")
Long getId();
@JsonProperty("description")
String description();
static Builder builder() {
return new Builder();
}
class Builder extends ImmutableOrderLine.Builder {
}
}
When the immutable values are generated with strictBuilder = false the generated ImmutableOrder.Builder class gets
the following methods for the order lines collection:
/** * Adds one element to {@link Order#getOrderLines() orderLines} list. * @param element A orderLines element * @return {@code this} builder for use in a chained invocation */publicfinalOrder.BuilderaddOrderLines(OrderLineelement) {
this.orderLines.add(Objects.requireNonNull(element, "orderLines element"));
return (Order.Builder) this;
}
/** * Adds elements to {@link Order#getOrderLines() orderLines} list. * @param elements An array of orderLines elements * @return {@code this} builder for use in a chained invocation */publicfinalOrder.BuilderaddOrderLines(OrderLine... elements) {
for (OrderLineelement : elements) {
this.orderLines.add(Objects.requireNonNull(element, "orderLines element"));
}
return (Order.Builder) this;
}
/** * Sets or replaces all elements for {@link Order#getOrderLines() orderLines} list. * @param elements An iterable of orderLines elements * @return {@code this} builder for use in a chained invocation */@JsonProperty("lines")
publicfinalOrder.BuilderorderLines(Iterable<? extendsOrderLine> elements) {
this.orderLines.clear();
returnaddAllOrderLines(elements);
}
/** * Adds elements to {@link Order#getOrderLines() orderLines} list. * @param elements An iterable of orderLines elements * @return {@code this} builder for use in a chained invocation */publicfinalOrder.BuilderaddAllOrderLines(Iterable<? extendsOrderLine> elements) {
for (OrderLineelement : elements) {
this.orderLines.add(Objects.requireNonNull(element, "orderLines element"));
}
return (Order.Builder) this;
}
When deserializing everything works as expected. Jackson deserializes the order lines as it finds the @JsonProperty("lines") on the orderLines(Iterable<? extends OrderLine> elements) method.
When generated with strictBuilder = true the generated ImmutableOrder.Builder class gets
the following methods for the order lines collection:
/** * Adds one element to {@link Order#getOrderLines() orderLines} list. * @param element A orderLines element * @return {@code this} builder for use in a chained invocation */publicfinalOrder.BuilderaddOrderLines(OrderLineelement) {
this.orderLines.add(Objects.requireNonNull(element, "orderLines element"));
return (Order.Builder) this;
}
/** * Adds elements to {@link Order#getOrderLines() orderLines} list. * @param elements An array of orderLines elements * @return {@code this} builder for use in a chained invocation */publicfinalOrder.BuilderaddOrderLines(OrderLine... elements) {
for (OrderLineelement : elements) {
this.orderLines.add(Objects.requireNonNull(element, "orderLines element"));
}
return (Order.Builder) this;
}
/** * Adds elements to {@link Order#getOrderLines() orderLines} list. * @param elements An iterable of orderLines elements * @return {@code this} builder for use in a chained invocation */publicfinalOrder.BuilderaddAllOrderLines(Iterable<? extendsOrderLine> elements) {
for (OrderLineelement : elements) {
this.orderLines.add(Objects.requireNonNull(element, "orderLines element"));
}
return (Order.Builder) this;
}
When deserializing Jackson fails with com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "lines" (class com.example.Order$Builder), not marked as ignorable (one known property: "id"]) at [Source: REDACTED ('StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION' disabled); line: 3, column: 13] (through reference chain: com.example.Order$Builder["lines"]).
The exception is thrown because there is no method annotated with @JsonProperty("lines") in the ImmutableOrder.Builder class. If the addAllOrderLines(Iterable<? extends OrderLine> elements) method get the annotation it all works again.
The text was updated successfully, but these errors were encountered:
When generating with
strictBuilder = true
, there is no@JsonProperty("lines")
annotation on any of themethods related to collections, which makes Jackson fail with an
UnrecognizedPropertyException
for the collections.A reproducer can be found here: https://github.com/bpasson/immutables-issue-1505
Detailed Example
Consider the following objects:
When the immutable values are generated with
strictBuilder = false
the generatedImmutableOrder.Builder
class getsthe following methods for the order lines collection:
When deserializing everything works as expected. Jackson deserializes the order lines as it finds the
@JsonProperty("lines")
on theorderLines(Iterable<? extends OrderLine> elements)
method.When generated with
strictBuilder = true
the generatedImmutableOrder.Builder
class getsthe following methods for the order lines collection:
When deserializing Jackson fails with
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "lines" (class com.example.Order$Builder), not marked as ignorable (one known property: "id"]) at [Source: REDACTED ('StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION' disabled); line: 3, column: 13] (through reference chain: com.example.Order$Builder["lines"])
.The exception is thrown because there is no method annotated with
@JsonProperty("lines")
in theImmutableOrder.Builder
class. If theaddAllOrderLines(Iterable<? extends OrderLine> elements)
method get the annotation it all works again.The text was updated successfully, but these errors were encountered: