After upgrading my project to Spring Boot 1.5.10, Lombok stopped working with Jackson. I mean the immutable creation of DTO when the field names in my objects do not match the fields in the 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 does not work, and I need to configure lombok as follows:
lombok.anyConstructor.addConstructorProperties = true
Does anyone know of any other way to create such objects using jackson + lombok without this lombok fix? Instead of this fix, I can use the 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 does not work with @JsonProperty("other-field-1-name") . Ofc, this can be done with a simple @JsonCreator , but maybe there is some way to use it with lombok using some constructor / jackson annotations?
java immutability jackson spring-boot lombok
Ands7
source share