-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
JsonTypeInfo.Id.MINIMAL_CLASS generates invalid type on sub-package #4983
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
Comments
Since handling of annotations (processing) is not here but in |
Minor note: will fix the Javadoc. |
I suspect this is working in unexpected way, not because child package handling didn't work, but because of the way base type is determined during serialization. This is an unfortunate consequence of of handling of "root values" (Java objects directly passed to So, although your intent is to consider You can see that if using a non-polymorphic wrapper and having value be To fix this, a mechanism would need to be added to try to retain and use actual Java class on which There might be an issue for this (old one), but no implementation. |
Ah. The issue that I think you hit is #1358. In the meantime, to anchor base type on write, you might be able to use (... if you didn't use
|
It is unclear to me how this is the same issue as #1358 and the bunch of related issues, as they seem quite specific to
My code does rely on
A bad workaround could also to add a field in
Looking around I understand the flatten annotations process as mostly related with Hence, either Or something more specific, around :
as we could analyze (again)
( Does this sound reasonnable? (if yes, I may contribute a PR). |
I linked to #1358 bit too quickly, without checking. It might not be the issue I was thinking for. Problem I am thinking of is definitely not specific to But basically, it'd be good to know exact class that is annotated with And yes, changes to But fwtw, while this issue might not on its own be important enough, the same issue is (I think) relevant for other problems... although cannot immediately recall which ones. |
I'm assessing if I could contribute:
The first option looks intrusive enough I could not foresee the raw impact. The second option would turn around JacksonAnnotationIntrospector: from:
into something like:
where |
Seems like serialization information being lost is the issue. |
@JooHyukKim Problem is that computing of "minimal" type id uses different information during serialization and deserialization, for root values (issue not affecting non-root values):
And by base type I mean class that has |
@blacelle I am open to different ideas, but in general Having said that, if you want to try prototyping I am happy to provide feedback. |
@cowtowncoder I opened a PR sketching how we could rely on the annotation holder for more accurate baseType computation in idResolver. |
(As a side-note, I'm a https://github.com/diffplug/spotless contributor. I may help if it felt relevant to wire Spotless to automatize formatting). |
Quick note: I don't think I want an auto-formatter, based on negative experiences I've had over time on level of effort to try to get things to work the way I would naturally format code and negligible value in 100% compliant formatting. I mention this just so it might save time from back and forth with various proposals on formatting improvements. |
Jackson: 2.18.2
I consider an interface with
@JsonTypeInfo(use = JsonTypeInfo.Id.MINIMAL_CLASS, property = "type")
.It works correctly with implementations in thr same package, but it fails with implementations in a child package.
Can be reproduced with:
OK:
KO:
Indeed, the type is invalid in
{type=.ChildrenSubPackage, someField=null}
as it should be.sub.ChildrenSubPackage
.Also, the javadoc seems invalid:
I suppose we want to read:
The text was updated successfully, but these errors were encountered: