Skip to content
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

failed to deserialize all interleaved elements for list #165

Closed
WangJiannan opened this issue Oct 28, 2015 · 9 comments
Closed

failed to deserialize all interleaved elements for list #165

WangJiannan opened this issue Oct 28, 2015 · 9 comments

Comments

@WangJiannan
Copy link

POJO:

@JacksonXmlRootElement(localName = "a")
public class A {
    public static class B {
        @JacksonXmlProperty(localName = "id")
        public String id;
    }

    @JacksonXmlProperty(localName = "b")
    @JacksonXmlElementWrapper(useWrapping = false)
    public List<B> bList;
}

XML:

<a>
   <b><id>id1</id></b>
   <any-tag/>
   <b><id>id2</id></b>
</a>

It's expected to get two elements 'id1' and 'id2' in bList, but only 'id2' is available after deserialisation.

related links:

@cowtowncoder
Copy link
Member

Please include Java POJOs included, as well as code. XML structure itself is not enough to know what exactly you are trying to do.

Please also note that reading of root-level Lists (that is, trying to directly read List or Collection) values is not a supported use case.

@WangJiannan
Copy link
Author

Sorry, I didn't state clearly. The description is updated and it's not the root-level List issue.

Actually, I find the second link is replied from you, so it seems you already know this issue. Would you consider to fix it?

@cowtowncoder
Copy link
Member

Thank you for the update.

The problem here is the <any-tag/>. Since it is in the middle of expected list of entries, it will break handling. I do not think this use case can be supported, unfortunately.

@WangJiannan
Copy link
Author

I think it's a very common use case when editing XML manually by many people. Nobody is willing to take care of tags order.
Is it a technical problem under Jackson framework or XML spec defines the behaviour?

@cowtowncoder
Copy link
Member

It is a limitation by Jackson module. XML allows any sequence of tags, repeating, and so forth.
I do not know if JAXB implementations would, for example, handle this.

@pswulius
Copy link

I ran into this issue parsing SVG documents. Polygons, paths, and rects are interleaved. Anyone know if there is any jackson solution at this time?

@cowtowncoder
Copy link
Member

@pswulius one thing that 2.9 will add in jackson-databind is @JsonMerge like so:

public class Container {
   @JsonMerge(OptBoolean.TRUE)
   public List<Point> points = new ArrayList<>();
}

which would not reset value, so multiple segments would effectively be merged.
I have not tried that with XML module but in theory it should work.
Before 2.9 you could still add "setPoints(List<> p) { }" method that similarly appends entries, but that is bit more intrusive.

This assuming that problem is not due to mixed content (that is, no unwrapped text/cdata sections), but due to disjoint sequences of elements with same name.

@pswulius
Copy link

Excellent. Thank you for the upcoming feature, and the current workaround. Both are great, and I've confirmed the setPoints(List<> p) workaround. Thank you for pointing that out!

@cowtowncoder
Copy link
Member

Since there is a work-around (or two) but no clear path on how to solve this in other ways, will close the issue: should be possible for users to find work-arounds on closed issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants