-
Notifications
You must be signed in to change notification settings - Fork 77
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
MismatchedInputException for XmlIDREF in generic interface attribute #144
Comments
Right, since this is related to JAXB annotation handling, moving to that repo first. |
Ok. So, I am not quite sure of intended semantics with But it is not 100% clear if you are intending object identities to be retained (this is usually needed to handle cyclic graphs). I hope to have time to look into this in near future but do not have immediate ideas of what is causing the issue reading back what Jackson wrote. |
Yes, the purpose is identity handling. I do have a rather complex object structure. With respect of single source of truth, I save each instance of This is the result of the serialization with Jackson, which looks totally fine to me:
My goal is to deserialize the JSON string and in return get an instance of In case I add However, adding abstract getters and setters to the interface and than use
I get no error and it seems the deserialization works. Is this the way to go? |
@raedma Yes, that usage looks fine -- I would be slightly worried about combination of generic types, identity (object id) and polymorphism (type id) as generics can sometimes cause problems -- but if it does work, great! JAXB annotations do work to some degree, but there may be some limitations since JAXB model handles things different from Jackson: and all information from JAXB annotations is essentially translate into model Jackson itself uses. Sometimes things do not translate 100%, or some combination might not work as expected. So I would recommend using Jackson annotations in this case, due to complexity. |
I do not know if this is the right location for the issue. If it is more related to handling JAXB annotations, I can move it.
I came across a problem when writing a test that first serializes an object to a string to JSON using Jackson and afterwards, tries to deserialize it. I tried to create a MWE based on the actual problem.
The underlying code uses JAXB annotations with additions for Jackson where necessary. The problem occurs for a generic attribute which itself is an interface. In the MWE there is a class
Model
with a generic attributevalue
of typeValueInterface
.value
itself is used as an@XmlIDREF
insideModel
. In the underlying tool I use aMemory
to storeModel
s andValue
s independently for reuse, as multipleModel
instances may use the sameValue
object.What I get is:
It seems Jackson is unable to resolve the
XmlIDREF
string, but rather expects thevalue
as a new node. I already tried different solution approaches, e.g. here and here, to tell Jackson that this is a reference to an object having an@XmlID
. Unfortunately, nothing helped.Any ideas?
I should mention that in the underlying code,
Value
itself is a subtype of some superclasses. Something like@JsonDeserialize(as = MyInterfaceImpl.class)
as mentioned here is not possible, otherwise I would not need an interface. The same approach works in JAXB for xml.MWE
Main
:Value.class
:ValueInterface
:Model
:Memory
:POM.xml
:The text was updated successfully, but these errors were encountered: