Open n00bman opened 12 years ago
Yes, I can reproduce this issue, added a unit test. Hope to resolve it.
I now understand what is happening -- property names ("inner" names) are being used for property maps, and result in conflicts, before wrappers would untangle everything. Not sure how to resolve this, but this might be solvable along with the question of whether wrapper should or should not be used for JSON.
This issue has been around for a while, I'm currently upgrading my application from org.codehaus.jackson v1 to com.fasterxml.jackson v2 and hitting this as a regression. Does anybody have a workaround or an ETA for a fix on it?
@madrob Unlikely this would get resolved any time soon.
Bumped into this issue in a project where I'm trying to replace GSON for JSON and xstream for XML with Jackson. Since I can't wrap the objects, I'll try to customize XmlSerializerProvider
to overcome this, either directly or through annotation processing.
@mikaelhg did you find a solution for this that didn't involve wrapping the objects?
@RikkiGibson Yes, but since this was the very last commit I made for my previous employer, I don't have access to the partial implementation which I got semi-working. Customizing collection XML serialization to look exactly like xstream was a giant PITA, and required reading through a lot of both Jackson XML and the relevant core code, and then stepping through it with a debugger. Maybe I'm just stupid, YMMV.
I doubt you are :) But since I have full control over my model classes and don't need superfast serialization performance I'm considering just using JAXB for XML serialization and using Jackson for JSON. Thanks for letting me know.
how to solve this problem?
Since nobody post a response, i propose a solution to wrapp list with a class and using @JacksonXmlElementWrapper(useWrapping = false).
@JacksonXmlRootElement(localName = "output")
@Getter
@Setter
public class Bean {
@JacksonXmlProperty(localName = "beanInfo")
private BeanInfoList beanInfo;
@JacksonXmlProperty(localName = "beanOther")
private BeanInfoList beanOther;
}
@Getter
@Setter
public class BeanInfoList {
@JacksonXmlElementWrapper(useWrapping = false)
@JacksonXmlProperty( localName = "item")
private BeanInfo[] bean;
}
@Getter
@Setter
public class BeanInfo {
private String name;
}
public static void main(String[] args) throws JsonGenerationException,
JsonMappingException, IOException {
ObjectMapper mapper = new XmlMapper();
Bean bean = new Bean();
BeanInfo beanInfo = new BeanInfo();
beanInfo.setName("name");
BeanInfo beanOther = new BeanInfo();
beanOther.setName("name");
BeanInfoList beanInfoList = new BeanInfoList();
beanInfoList.setBean(new BeanInfo[] { beanInfo });
bean.setBeanInfo(beanInfoList);
BeanInfoList beanOtherList = new BeanInfoList();
beanOtherList.setBean(new BeanInfo[] { beanOther });
bean.setBeanOther(beanOtherList);
String output = mapper.writeValueAsString(bean);
System.out.println(output);
}
This will post as result
`
<beanOther>
<item>
<name>name</name>
</item>
</beanOther>
`
Hi, I'm using latest release 2.0.1 and I've got a problem with serializing/deserializing xml (everything works fine in JSON). I'd like to have such a xml:
This example give getter definition conflict.
If I change
then all work fine and I've got
but if I try to deserialize it then I've got setter definition conflict...