-
-
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
@JacksonXmlProperty with attributes raises an exception when used with @JsonIdentityInfo #248
Comments
I'm running into a similar issue (using v2.8.9) when trying to customize the
then I run into the same exception. If I remove the use of the
then the serialization occurs without error. Maybe this will give further insight into the issue. |
Thank you. Yes, I think the whitespace causes issues here -- white space is a problem with XML because while it 99% of the time is meaningless, and users/devs rarely rely on it, it has to be retained and can not be discarded in general, without knowing it is safe to do so. I don't know exact details of this specific case, but I am not surprised that this could be related. |
So, did anyone figure out how to make the make a the XmlMapper print using the customized PrettyPrinter? |
I found the answer, we need to use the Xml pretty printer and define a custom Xml indenter. An Indenter like the following would do the trick: private static class MyIndenter
implements DefaultXmlPrettyPrinter.Indenter, Serializable
{
private static final long serialVersionUID = 1L;
@Override
public void writeIndentation(final JsonGenerator p_jsonGenerator, final int p_level) throws IOException
{
p_jsonGenerator.writeRaw(new char[] { '\n' }, 0, 1);
for (int l = 0; l < p_level; l++)
{
p_jsonGenerator.writeRaw(new char[] { ' ', ' ', ' ', ' ' }, 0, 4);
}
}
@Override
public void writeIndentation(final XMLStreamWriter2 p_xmlStreamWriter2, final int p_level) throws XMLStreamException
{
p_xmlStreamWriter2.writeRaw(new char[] { '\n' }, 0, 1);
for (int l = 0; l < p_level; l++)
{
p_xmlStreamWriter2.writeRaw(new char[] { ' ', ' ', ' ', ' ' }, 0, 4);
}
}
@Override
public boolean isInline()
{
return false;
}
} You can then use it in your XmlMapper: final DefaultXmlPrettyPrinter xmlPrettyPrinter = new DefaultXmlPrettyPrinter();
final DefaultXmlPrettyPrinter.Indenter customIndenter = new MyIndenter();
xmlPrettyPrinter.indentObjectsWith(customIndenter);
new XmlMapper()
.writer(xmlPrettyPrinter)
.writeValueAsString(myObject) |
I'm running into an issue with version 2.8.9, which might be related to issue #81 / #82: I'm trying to serialize an object graph with a circular reference using JsonIdentityInfo. This works well unless the referenced object has properties marked with @JacksonXmlProperty( isAttribute = true )
Minimal example below:
Expected output:
Instead the exception:
is thrown. Removing the JsonIdentityInfo annotation solves the issue as well, i.e. name is correctly serialized as an attribute, but then a circular reference causes a stack overflow - obviously.
The text was updated successfully, but these errors were encountered: