Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix : Cannot read
Optional
s written withStdTypeResolverBuilder
, from[jackson-modules-java8#86]
#4838Fix : Cannot read
Optional
s written withStdTypeResolverBuilder
, from[jackson-modules-java8#86]
#4838Changes from 3 commits
7089146
6d6de03
30d2cb0
cde7eb8
c36b8f2
a683b1a
42ba9a6
7381be2
e800e18
636792a
e4fd2f0
0fc9a94
0f3ffcb
2f19d45
e374faa
de92568
4ac30d3
1b3f3d9
940034d
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Ok. I think this makes sense, except for one problem --
JsonToken.VALUE_STRING
works for some cases, not for others. Problem is, we do not actually know the expected shape of contained value. Later on, test can be broken; I'll add a note where and how, below.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 am really not sure how to fix this. I understand why type id would be needed, for
AtomicReference
/Optional
wrapper. Unfortunately there is a key problem: nothing else will be written for these wrappers.Unless... unless I guess if we decide that for the specific case of polymorphic value, there is.
And I think the only possibility, there, is extra wrapper array. I'll see if that works.
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.
Sigh. Nope. Was not able to make this work overall.
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.
At least if we have more test case 👍🏼👍🏼
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.
@cowtowncoder I modified the test via de92568, to configure
StdTypeResolverBuilder
to use appropriate inclusion scheme for each mapper. Seems like that's way to go?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.
Perhaps? I am not sure which cases to focus most; ones with
@JsonTypeInfo
introduced ones or Default Typing (I know, it's reported wrt Default Typing but in a way@JsonTypeInfo
cases are more important -- Default Typing having security concerns).Another confounding factor is that for
String
andInteger
, type id MUST NOT be written ("natural" types), nor expected.It's a mess. :)
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.
But no matter what, we really cannot use
JsonToken.VALUE_STRING
for all cases because some values are serialized as Objects (Maps, most POJOs), others as Arrays (Collection
s) and those cases would not work with this type id.Yet there is also no way for
ReferecenTypeSerializer
to know for sure value shape.This is why I think we actually must use JSON Array wrapper for Type Id case to know exact shape for just this case (in theory JSON Object but that would require bogus key for single entry; array seems cleaner).
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 am starting to think this situation (Default Typing overrides
@JsonTypeInfo
) is inevitable, due to Jackson does heavy lifiting during serialization.I don't think there is easy, sensible way to introspect all the way from
Foo<T>
->AtomicRference<T>
->Animal
to get configured type information, during runtime.So maybe we can either...
Optional<String>
and create separate milestone for this override case by pushing some tests astofix
.. ortofix
and come back later in the future when we are in best shape to do so.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 think the problem is more with the "missing" serialization for
Optional
, actually. For non-polymorphic case it is sort of ok, as long as POJO typing is defined. Basically following 2 serialize to identical JSON:this is ok because no Type Id needs to be added anywhere.
But if (polymorphic) Type Id needs to be added, there is only place for one of Type Ids (
MyPojo
) -- forOptional
there is no JSON value to modify/include because it is invisible, unlikeList
and others for which there is JSON Array.If there was JSON Array to represent
Optional
level things would be easier.So for
Collection
case,As.WRAPPER_ARRAY
we might have something like:where extra "wrapper Array" is added around
Multiple
,List
as well asMyPojo
element)s_s (depending on details of@JsonTypeInfo
or Default Typing -- here assume it is applicable to all ofMultiple
,List
andMyPojo
).This is not really possible with
Optional
because nothing is written to representOptional
Now: in theory we could consider doing something similar to
EnumSet
where Class name as type id is actually polymorphic -- and we might be able to do the same with optional. But it would have to replace Type Id of thing contained (and only works for Class Name type id, but that's probably to be expected).But I suspect that would be even more work.
As to "solving" reported case... I am still worried I don't fully understand the behavior before and after change. We'd need to, I think, verify exact JSON being produced and not simply checking round-tripping.
My concern is specifically that we end up changing serialization output and breaking other usage that is not covered by test cases.
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.
True, this is getting bigger than I imagined I agree with your concerns wrt serialization output. Knowing that the serialization output changed versions back, (2.8 -> 2.9) complicates things I think.
We might even consider current output as expected behavior and suggest to try work around or something, for cases where they update [ 2.8 -> 2.9 or later like 2.18 .
In any case, I will close this off for now and would like to get back to taking steps toward 3.0 -- I will leave some closing comments