-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow using @JsonPropertyOrder
with any-property (@JsonAnyGetter
)
#4396
Conversation
One quick note: I think ordering within "any-getter" group can be out of scope as users can use specific Otherwise, I'll have to read this couple of times. I guess it would make sense to try to make any-getter placeholder work similar to "simple" properties, so sorting works. But I wonder if there are complications wrt attempts to link/unlink, as well as ignoral. This because formerly "name" of any-getter hasn't had any effect and could not have accidentally ignored (for example) by a regular property with same name having |
Valid point with respect to
Could you explain a bit more on link/unlink? |
Link/unlink: different getter/setter methods, fields, get "linked" if they have same logical name, either implicit (default) or explicit (rename), into a single logical property. So all I am wondering is if there was a case like:
where any-setter would be ignored due to name match. Or something similar related to accidentally matching names. |
Fortunately, seems to work wrt link/unlink-ed properties 👍🏼. Added more tests via 85ae52e. |
src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java
Show resolved
Hide resolved
src/test/java/com/fasterxml/jackson/databind/ser/JsonPropertyOrderWithAnyGetter4388Test.java
Show resolved
Hide resolved
src/main/java/com/fasterxml/jackson/databind/ser/BeanSerializerFactory.java
Show resolved
Hide resolved
@@ -218,6 +218,8 @@ public void serializeAsField(Object pojo, JsonGenerator jgen, | |||
writer.serializeAsField(pojo, jgen, provider); | |||
} else if (!jgen.canOmitFields()) { // since 2.3 | |||
writer.serializeAsOmittedField(pojo, jgen, provider); | |||
} else if (writer instanceof AnyGetterWriter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WIP : Contemplating on how should we optimize this check...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried referring to other writer/serializers and it turns out instanceof
here check seems sort of reasonable.
Would this still be considered for 2.18, @cowtowncoder? |
@JooHyukKim potentially yes. |
AnnotatedMember accessor, JsonSerializer<?> serializer) | ||
{ | ||
super(parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually safe? Doesn't it copy settings of "parent"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was intended actually. Copying seemed safer than holding reference to original BeanPropertyWriterpropert propert that is soon to be a any-getter.
I referenced same pattern in VirtualBeanPropertyWriter
, UnwrappingBeanPropertyWriter
, like below.
Do you think there would be side effect?
public UnwrappingBeanPropertyWriter(BeanPropertyWriter base, NameTransformer unwrapper) {
super(base);
_nameTransformer = unwrapper;
}
protected UnwrappingBeanPropertyWriter(UnwrappingBeanPropertyWriter base, NameTransformer transformer,
SerializedString name) {
super(base, name);
_nameTransformer = transformer;
}
Just a heads up: as much as I'd like to get this merged, I think it will have to wait for 2.19 -- I am currently trying hard to close up remaining issues and I think this is relatively high-risk change. |
Agreed👍🏼👍🏼. No need to risk things. |
@JooHyukKim Would need to get this rebased or recreated against |
Closing in favor of #4775 |
(For after Property Introspection Rewrite)
This PR resolves...
1.. #4388
2.. part of #2592
- AnyGetter with JsonInclude + JsonFilter combo
Modifications
This PR basically...
AnyGetterWriter
extendBeanPropertyWriter
.notes