jackson-databind icon indicating copy to clipboard operation
jackson-databind copied to clipboard

Add a feature to require "complete" creators; that is, to prevent use of setters if using property-based creator

Open cowtowncoder opened this issue 11 years ago • 1 comments

(note: migrated from https://github.com/FasterXML/jackson-core/issues/154 by @benson-basis)


I was surprised to learn that Jackson will combine @JsonCreator with patching properties. Even, in particular, protected final properties. When I wrote a mixin with @JsonCreator, I thought that I was specifying the one and only way (give or take other annotated constructors) to construct the class.

I wish that there was an option to set that would have this effect, and throw rather than patch a property if the JsonCreator is not usable in a deserialization.


My view of the semantics I want is

@JsonCreator(Complete = true)

If any @JsonCreator says this, then if Jackson feels a need to call a setter or patch a property, it should throw instead. For this to work, my other idea about JsonAnySetter versus JsonCreator has to be done, too.

cowtowncoder avatar Sep 30 '14 04:09 cowtowncoder

FWIW, auto-detection of final fields may be already disabled by

objectMapper.disable(MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS);

so that final fields can be only used for reading values, but not modifying them.

But this still leaves the possibility of having non-final fields or setters. So I take the remaining problem being that of dropping all setters, including "any setter".

cowtowncoder avatar Oct 03 '14 05:10 cowtowncoder