I'm developing a REST application using application/json
Content-Type (server). I'm developing the REST client library for it as well (client). Both server and client use the same Jackson annotated classes/resources.
One of my server use cases includes adding a field which should be write-only (enable only deserialization). I do it like this:
public class MyClass {
@JsonProperty(access = WRITE_ONLY)
private String field;
...
}
However, since this class is used on the client side too, I am unable to send value to this field because the serialization processing skips it. I want the client to be able serialize this field. The server and client use separate object mappers.
I can use separate implementations of JsonSerializer<MyClass>
and set it to the object mapper but this mean that I have to serialize all other fields manually. I don't want this.
I am wondering, if there is some way to instruct object mapper (or inject something into it) to handle such field differently?