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

Allow @JsonAnySetter on Creator constructors

Open JooHyukKim opened this issue 5 months ago • 7 comments

resolves #562

JooHyukKim avatar Feb 03 '24 14:02 JooHyukKim

Impressive. I am bit hesitant to consider this as one more thing before work on Property Introspection rewrite, but no harm in figuring out how this could work. Added some notes.

cowtowncoder avatar Feb 04 '24 02:02 cowtowncoder

Impressive. I am bit hesitant to consider this as one more thing before work on Property Introspection rewrite,

I concur. And also in the issue #562, this feature is to get included in 3.x.

So I think we can safely consider this feature only after Property Introspection rewrite.

but no harm in figuring out how this could work. Added some notes.

Thankssss! I will keep them updated

JooHyukKim avatar Feb 04 '24 02:02 JooHyukKim

Cool, this is much improved. I'll make tiny changes, wrt suggestions I added.

cowtowncoder avatar Feb 10 '24 00:02 cowtowncoder

@JooHyukKim Ok, I made a few changes that I think help, including validation that only one "any-setter" is specified.

I was also wondering if it wouldn't make sense to add knowledge of "any-setter" creator property directly into PropertyValueBuffer (make it take SettableAnyProperty). Also I think validation wrt DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES need to be able to skip check for placeholder there.

cowtowncoder avatar Feb 10 '24 01:02 cowtowncoder

I was also wondering if it wouldn't make sense to add knowledge of "any-setter" creator property directly into PropertyValueBuffer (make it take SettableAnyProperty).

Do you mean do the PropertyValueBuffer construction with anySetter in it in the first place, in earlier part of _deserializeUsingPropertyBased? If so, sounds like an idea.

Also I think validation wrt DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES need to be able to skip check for placeholder there.

Placeholder? 🤔 Could u elaborate a bit more?

JooHyukKim avatar Feb 10 '24 01:02 JooHyukKim

I was also wondering if it wouldn't make sense to add knowledge of "any-setter" creator property directly into PropertyValueBuffer (make it take SettableAnyProperty).

Do you mean do the PropertyValueBuffer construction with anySetter in it in the first place, in earlier part of _deserializeUsingPropertyBased? If so, sounds like an idea.

Right.

Also I think validation wrt DeserializationFeature.FAIL_ON_NULL_CREATOR_PROPERTIES need to be able to skip check for placeholder there.

Placeholder? 🤔 Could u elaborate a bit more?

What I mean is to test to see that if this setting is enabled, it will not cause failure since property that represents "any-setter" has no associated value. So by placeholder I meant constructor parameter that is not a "real" parameter, similar to how injectable value isn't required to come from input.

cowtowncoder avatar Feb 10 '24 01:02 cowtowncoder

I was also wondering if it wouldn't make sense to add knowledge of "any-setter" creator property directly into PropertyValueBuffer (make it take SettableAnyProperty).

cc/ @cowtowncoder Implemented as suggested in commit https://github.com/FasterXML/jackson-databind/pull/4366/commits/8612433174444c364f704fa6a82c802baba3f959. Apologies in advance for formatter taking up large portion.

IMO, this new version seems more appropriate in that we don't handle values twice --first buffering in PropertyValueBuffer then transfer to map for AnySetter parameter.

JooHyukKim avatar Feb 10 '24 06:02 JooHyukKim