I have the following bean that describes a mongo document, and that uses lombok:
@JsonDeserialize(builder = MyClass.MyClassBuilder.class)
@Builder(toBuilder = true)
@Value
public class MyClass {
private final String id;
@Default
private final String field = "defaultValue";
@JsonPOJOBuilder(withPrefix = "")
public static class MyClassBuilder {}
}
When deserializing {"id": "document"} with jackson, I end-up with a bean containing both id=document and field=defaultValue because it used the builder that provide a default value for the field.
Now what I want to do, is to have the defaultValue set for documents coming out of the database (coming from ReactiveMongoTemplate). But it seems to use the all args constructor even if I set it private (or some reflect black magic)
So the main question is: is it possible to tell spring to use the builder to build the bean when coming out of the database?