I have an application where I'm trying to implement partial updates with PATCH
requests.
For now I have DTO objects that retrieve data from HTTP, and are mapped to JPA entities with the Orika library (configured with mapNulls = false
)
This worked fine until now, but it does not work with partial updates since my DTO objects do not differentiate null
values from not provided values. Then if I explicitly set a field to null
, Orika ignores it and the value remains the same.
Then I considered using generic objects instead of DTO objects, but by doing this I would lose the benefits from the @JsonProperty
annotation which is very useful to control which field is access = Access.READ_ONLY
or not.
How do I benefit from the generics world and the DTO world ? Is there a way to deserialize into a dynamic DTO ?
This is not supported right now. All you can do is to have two distinct MapperFactory one configured with mapNulls=true other with mapNulls=false. Since it's plain Java code it can be done easily without too much effort.
You will have in the end one MapperFacade for PATCH method and the other for creation update.
It's better to keep DTO as a matter of service contract.