Comments (10)
@madrob Unlikely this would get resolved any time soon.
from jackson-dataformat-xml.
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?
from jackson-dataformat-xml.
Yes, I can reproduce this issue, added a unit test. Hope to resolve it.
from jackson-dataformat-xml.
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.
from jackson-dataformat-xml.
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.
from jackson-dataformat-xml.
@mikaelhg did you find a solution for this that didn't involve wrapping the objects?
from jackson-dataformat-xml.
@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.
from jackson-dataformat-xml.
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.
from jackson-dataformat-xml.
how to solve this problem?
from jackson-dataformat-xml.
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
<output> <beanInfo> <item> <name>name</name> </item> </beanInfo> <beanOther> <item> <name>name</name> </item> </beanOther> </output>
from jackson-dataformat-xml.
Related Issues (20)
- `ArrayIndexOutOfBoundsException` thrown for invalid ending XML string when using JDK default Stax XML parser HOT 2
- Upgrade to 2.16.0 failing with `NoSuchMethodError` for `JavaType.isIterationType()` HOT 4
- If there are HTML tags within XML tags, @JacksonXmlText will assign incorrect values to the content. HOT 7
- Java bean serialization XML encoding problem HOT 1
- Without setting `@JsonCreator` for the POJO, the `required` attribute in `@JsonProperty` is not checked HOT 1
- Disabling wrapper on list (e.g. defaultUseWrapper = false) does not serialize/deserialize null lists as expected HOT 2
- When the `localName` property of `@JacksonXmlProperty` is not set, the `required` of `@JsonProperty` does not detect the property name of POJO HOT 10
- java.lang.IllegalArgumentException: Cannot deserialize value of type `java.util.ArrayList<RetInfArryDTO> from Object value (token `JsonToken.START_OBJECT`) HOT 8
- Add `XmlMapper.createGenerator(XMLStreamWriter)` and `XmlMapper.createParser(XMLStreamReader)` overloads
- Support use of xsi:type for polymorphic deserialization (FromXmlParser.Feature.AUTO_DETECT_XSI_TYPE)
- Support Encoding option when writing XML HOT 1
- `JacksonXmlAnnotationIntrospector.findNamespace()` should properly merge namespace information
- xmlMapper.readValue( xmlString , Bean.class ) for Single Boolean Value does not get the value defaults with false HOT 1
- XML serialization of floating-point infinity is incompatible with JAXB and XML Schema HOT 2
- native compilation error with version 2.17.0 of com.fasterxml.jackson.dataformat:jackson-dataformat-xml HOT 3
- Deserializing fails when using builder classes with `Iterable` Collection setters HOT 11
- Deserialization into collection does not respect namespaces HOT 4
- Cannot construct instance of `PEPSchema.MEMBER` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('Yes1') HOT 8
- Conflicting Getter Definitions for Different List Properties with Same Element as Content (dup of #27) HOT 4
- Nesting depth in `XmlReadContext` is not incremented/decremented on JsonToken.START_OBJECT/JsonToken.END_OBJECT HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jackson-dataformat-xml.