Git Product home page Git Product logo

Comments (10)

cowtowncoder avatar cowtowncoder commented on July 27, 2024 2

@madrob Unlikely this would get resolved any time soon.

from jackson-dataformat-xml.

madrob avatar madrob commented on July 27, 2024 1

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.

cowtowncoder avatar cowtowncoder commented on July 27, 2024

Yes, I can reproduce this issue, added a unit test. Hope to resolve it.

from jackson-dataformat-xml.

cowtowncoder avatar cowtowncoder commented on July 27, 2024

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.

mikaelhg avatar mikaelhg commented on July 27, 2024

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.

RikkiGibson avatar RikkiGibson commented on July 27, 2024

@mikaelhg did you find a solution for this that didn't involve wrapping the objects?

from jackson-dataformat-xml.

mikaelhg avatar mikaelhg commented on July 27, 2024

@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.

RikkiGibson avatar RikkiGibson commented on July 27, 2024

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.

zhangqunshi avatar zhangqunshi commented on July 27, 2024

how to solve this problem?

from jackson-dataformat-xml.

Vincent3039 avatar Vincent3039 commented on July 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.