-
-
Notifications
You must be signed in to change notification settings - Fork 221
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
Serialization of a polymorphic class As.Property with Identity information doesn't work #81
Comments
As a note, this happens when trying to write an object as a reference, only the id and not the full object. |
I found two ways to fix this issue:
Currently, I've built locally a SNAPSHOT version of databind and dataformat xml with the second solution and using that in the project, and it works pretty well. |
This seems to be a pretty old issue, but I've just encountered it in 2.8.9: @JsonIdentityInfo( generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "id" )
@JacksonXmlRootElement( localName = "a" )
public class A {
public static void main( String[] args ) throws IOException {
final A a = new A();
a.b = new B(); //B has a reference back to A
a.b.setA( a );
final XmlMapper mapper = new XmlMapper();
final String json = mapper.writeValueAsString( a );
System.out.println( json );
}
private B b;
private String name = "test";
@JacksonXmlProperty( isAttribute = true ) //test runs with isAttribute set to false (but serializes name as an elment
public String getName() {
return name;
}
//other getter/setter omitted for brevity Expected output: <a name="test">
<id>1</id>
<b>
<a>1</a>
</b>
</a> Instead the exception: Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Unexpected IOException (of type java.io.IOException): javax.xml.stream.XMLStreamException: Trying to write an attribute when there is no open start element. is thrown. Removing the JsonIdentityInfo annotation solves the issue as well, i.e. name is serialized as an attribute, but then the circular reference causes a stack overflow. |
@lightbringer Please file a new issue -- I try not open closed issues since this makes it difficult to track where fixes go. This may or may not be same or related issue; it makes sense to add a reference this as possibly related. |
Basically, XmlBeanSerializer#serializeWithType doesn't take into account Object Id when it sets "NextIsAttribute". I'll try to attach a unit test, probably tomorrow.
The text was updated successfully, but these errors were encountered: