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

JSOG usage of @JsonTypeInfo and @JsonIdentityInfo(generator=JSOGGenerator.class) implies failure for deserialization #669

Closed
ericali78 opened this issue Jan 6, 2015 · 6 comments

Comments

@ericali78
Copy link

First happy new year to everybody !
Deserialization seems to work with JSOGGenerator. However when adding @JsonTypeInfo (need this in a model object that have superclass), it does not succeed to.

Sample to reproduce in JSOGTest.java :

@JsonIdentityInfo(generator=JSOGGenerator.class)
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@Class")
public static class Inner {
public String bar;
}
In a more global way, the @Class attribute does not seem to be handle or lead to a conflict with @ref management.
Does somebody succed to handle that ? thank you .
Sorry if double post in JSOG jackson plugin is too much (dunno wich is the best place to put/solve)

@ericali78 ericali78 changed the title JSOG usage of @JsonTypeInfo and @JsonIdentityInfo(generator=JSOGGenerator.class) implies failure for deseralization JSOG usage of @JsonTypeInfo and @JsonIdentityInfo(generator=JSOGGenerator.class) implies failure for deserialization Jan 6, 2015
@cowtowncoder
Copy link
Member

May be related to the problem of injecting multiple metadata properties. But how does this fail?
I assume serialization works as expected?

@ericali78
Copy link
Author

Hello,
Thanks for your aswer.
Yes the serialization is ok.
-> Serialized to: {"@id":"1","foo":"foo","inner1":{"@Class":"com.voodoodyne.jackson.jsog.JSOGTest$Inner","@id":"2","bar":"bar"},"inner2":{"@ref":"2"}}

But when attempting to deserialize it fails because jacksson thinks that "inner1":{"@Class":"com.voodoodyne.jackson.jsog.JSOGTest$Inner","@id":"2","bar":"bar"} represents an objectid or reference

stack trace :
Caused by: java.lang.NullPointerException
at com.voodoodyne.jackson.jsog.JSOGRefDeserializer.deserialize(JSOGRefDeserializer.java:38)
at com.voodoodyne.jackson.jsog.JSOGRefDeserializer.deserialize(JSOGRefDeserializer.java:18)
at com.fasterxml.jackson.databind.deser.impl.ObjectIdReader.readObjectReference(ObjectIdReader.java:136)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectId(BeanDeserializerBase.java:1045)
)

@stickfigure
Copy link
Contributor

I created a PR that adds a failing test case:

#672

I'm not quite sure what is going on. I have a test case for this in the jsog-jackson code and it looks like jackson is trying to deserialize a ref, even the first time it sees the object (when it is a full object with id). But the failure in the PR above looks a little different. I suspect it has the same root cause.

cowtowncoder added a commit that referenced this issue Jan 8, 2015
@cowtowncoder
Copy link
Member

So the problem is due to interaction between type and object ids. Will need to see what to do with that.

@cowtowncoder cowtowncoder added this to the 1.9.13 milestone Jan 8, 2015
@cowtowncoder
Copy link
Member

Turned out to be relatively easy to fix. Phew! For a while thought might be trickier.

One thing that is clear, however, is that for more complex Object Ids (more than a single key/value pair), code would become a pretzel. But that's neither here nor now, so we're good for time being. :)

@ericali78
Copy link
Author

Great job
Thank you !

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

3 participants