Serialization of transient fields with public getters (add MapperFeature.PROPAGATE_TRANSIENT_MARKER)
Currently when my field is transient (with a public getter) it is serialized. I can put @JsonIgnore annotation to tell jackson to not serialize it. But with this approach my object is coupled directly with jackson. Is it possible to add such functionality to "tell" Jackson globally to not serialize transient fields ? Via ObjectMapper#SerializationFeature/Visibility or something different.
The problem is that there is no assumption that 'transient' in field means that the logical property, as accessed using getter/setter is to be ignored. It would be possible to change this logic, but that is a backwards incompatible functional change; so most likely it should be a new MapperFeature.
I can take this issue to mean requesting of such a change.
In short term, what you can do is to sub-class JacksonAnnotationIntrospector and override hasIgnoreMarker() to return true for fields that are transient. This would then work as if field had explicit @JsonIgnore. So this should make it work the way you want I think.
Thanks, it would be good to have such functionality. I will try now with your solution.
Looked at this briefly, and was about to add a MapperFeature, but then remembered the underlying complication: removal of transient fields occurs too early in the processing (by AnnotatedClass).
It would need to occur at a later point. Will see how easy that would be.
Turned out easy enough to implement: the default behavior did not change, but if enabling: MapperFeature.PROPAGATE_TRANSIENT_MARKER, transient is handled same way as a @JsonIgnore on field would, leading to removal of the whole logical property unless there is an explicit @JsonProperty to counteract.
Default handling was not changed due to backwards-compatibility concerns, although for Jackson 3.x we could definitely consider changing of defaults.