After updating my project to Spring Boot 1.5.10 Lombok stopped working correctly with Jackson. I mean immutable DTOs creation, when field names in my objects are not same as fields in json request:
@Value
@Builder
public class MyImmutableDto implements Serializable {
@JsonProperty("other-field-1-name")
private final BigDecimal myField1;
@JsonProperty("other-field-2-name")
private final String myField2;
and a lot of fields there...
}
So, after updating Spring Boot to 1.5.10 this code isn't working, and I need to configure lombok like that:
lombok.anyConstructor.addConstructorProperties = true
Does anyone know any other way to create such objects with jackson + lombok without this lombok fix?
Instead of this fix I can use following code: @JsonPOJOBuilder
and @JsonDeserialize(builder = MyDto.MyDtoBuilder.class)
:
@Value
@Builder
@JsonDeserialize(builder = MyDto.MyDtoBuilder.class)
public class MyDto implements Serializable {
// @JsonProperty("other-field-1-name") // not working
private final BigDecimal myField1;
private final String myField2;
private final String myField3;
and a lot of fields there...
@JsonPOJOBuilder(withPrefix = "")
public static final class MyDtoBuilder {
}
}
But it is not working with @JsonProperty("other-field-1-name")
.
Ofc, it can be done by simple @JsonCreator
, but maybe there is some way to use it with lombok using some constructor/jackson annotations?