-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
Make JsonGenerator::writeTypePrefix
method to not make a WRAPPER_ARRAY
when typeIdDef.id == null
#1356
Conversation
…_ARRAY when `typeIdDef.id == null`
typeIdDef.id == null
JsonGenerator::writeTypePrefix
method to not make a WRAPPER_ARRAY
when typeIdDef.id == null
One process thing: beyond code review, before merging I'd need CLA: https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf (unless already done earlier; one CLA per contributor is fine for all Jackson contributions). |
Ah ok: so we don't want type id like:
which I totally agree with. However, actual Alternatively another maybe even better way would be to consider One problem with changes to Type Id handling is that it is feature Oh: which reminds me: we'd definitely need a test added to |
I have to say that I don't have sufficient visibility into the design idea of the Though at least it's thought-provoking, and this was my goal. I support the idea to "consider I'll do the drill related to CLA and improve the change in this PR some time soon. Thanks for your feedback as usual. |
I did the changes and sent the signed agreement. |
@Gems looks good -- did just a quick first pass, need to take some more time, but I think this should work. Got CLA so we are good with that too. Will try local build to hopefully ensure that format modules (esp. YAML, XML) are ok with this change (should be but it's potentially brittle area) |
JsonGenerator::writeTypePrefix
method to not make a WRAPPER_ARRAY
when typeIdDef.id == null
JsonGenerator::writeTypePrefix
method to not make a WRAPPER_ARRAY
when typeIdDef.id == null
…miliar with intent)
Ok, some of my logic changes proved wrong wrt short-circuiting handling: cause issue with YAML. Will revert. |
…or values, with native Type Ids too)
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.
LGTM -- made some stylistic changes, but essentially included as-is.
Tests for #4772, mark as fixed (actually fix via FasterXML/jackson-core#1356 for 2.19.0)
This PR addresses GitHub issue #4772.
Summary
In certain cases where
@JsonTypeInfo
is used withJsonTypeInfo.Id.DEDUCTION
,typeDef.id
may resolve tonull
. For example, in the referenced issue, this occurs with a class based on theCollection
interface, resulting intypeDef.id
beingnull
.Change Details
This update modifies the
sonGenerator::writeTypePrefix
method so that it doesn’t generate a wrapping array with a"null"
key for classes with anull
typeDef.id
. The current behavior, which includes an unnecessary wrapping array labeled by"null"
, can be misleading. By skipping this wrapper, we aim to make the serialization output more intuitive and aligned with user expectations.Rationale
The previous behavior of adding a wrapping array with a "null" key was confusing and did not provide meaningful value to users. Removing it simplifies the output and makes the serialization format clearer, especially in cases involving classes based on generic interfaces like
Collection
.Impact
This change will make the output format more predictable and consistent, especially for users employing
@JsonTypeInfo
withJsonTypeInfo.Id.DEDUCTION
. Existing tests and validation tools should ensure that this change does not disrupt compatibility with existing deserialization setups.