Skip to content
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

Change TypeSerializerBase to skip generator.writeTypePrefix() for null typeId #3373

Closed
cowtowncoder opened this issue Jan 16, 2022 · 2 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

cowtowncoder commented Jan 16, 2022

(note: offshoot of FasterXML/jackson-core#584)

It seems that there are cases where Type Id resolution would be best handled by avoiding call altogether: specifically, when there is no Type Id passed (that is, null is passed).
This is handled in method TypeSerializerBase.writeTypePrefix(); and requires some matching changes in TypeSerializerBase.writeTypeSuffix() as well.

The idea here is to:

  1. Return null from writeTypePrefix() if no typeId passed.
  2. In writeTypeSuffix(), skip processing if WritableTypeId passed is null (but not necessarily if WritableTypeId.id is null)

and hopefully this will allow essentially avoiding the write, in a safe and clean manner.
The one possible complication case is that of if some existing code relied on null typeId being passed (null for WritableId would never work, would NPE). There isn't any good reliable way to catch that but... let's hope 2.14 RCs give a chance for downstream deps to check.

@cowtowncoder
Copy link
Member Author

cc @ jonfreedman

@cowtowncoder cowtowncoder added this to the 2.14.0 milestone Jan 16, 2022
@cowtowncoder
Copy link
Member Author

Ok, this doesn't quite work (see f.ex #4354) -- if idFromValue() returns null for typeId to use, call to write type prefix is indeed skipped... but for most embedding mechanisms this will be missing parts of output that cannot be omitted.

Not sure what'd be the best way to handle this, just noting the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant