I\'m currently playing around with Jackson\'s de/serialization features and I encountered a problem, I don\'t know how to solve.
During my test the @JsonProper
I had the same problem, with a similar setup. The problem is in the test input data. Basically, writeValueAsBytes()
will ignore the password while serializing exactly as instructed by the annotation.
Note that, Access.WRITE_ONLY
basically means "SetterOnly" or "DeserializationOnly" not the other way around.
add the line for your ObjectMapper:
mapper.disable(MapperFeature.USE_ANNOTATIONS);
Ignoring all the annotations can be problematic. To handle a finer configuration you can implement your custom JacksonAnnotationIntrospector
:
public class IgnoreJacksonWriteOnlyAccess extends JacksonAnnotationIntrospector {
@Override
public JsonProperty.Access findPropertyAccess(Annotated m) {
JsonProperty.Access access = super.findPropertyAccess(m);
if (access == JsonProperty.Access.WRITE_ONLY) {
return JsonProperty.Access.AUTO;
}
return access;
}
}
Then, after instantiating the mapper:
mapper.setAnnotationIntrospector(new IgnoreJacksonWriteOnlyAccess());