tweets
tweets

Reputation: 1

jackson fasterxml multiple elements with the same name not aligned together

<A>
        
        <Ser name="cluster1" localroot="search" branch="feature>
        </Ser>
        <PR localroot="search" msg="Merge the pr."/>

        <Ser name="cluster2" localroot="clone" branch="change-fix>
        </Ser>
        <PR localroot="clone" msg="Merge the pr."/>
</A>

Trying to read the same using XmlMapper.readValue() but It is just reading the last value of both & not the list.

Note: this works well when Xml is:


    <A>
            <Ser name="cluster1" localroot="search" branch="feature>
            </Ser>
            
            <Ser name="cluster2" localroot="clone" branch="change-fix>
            </Ser>
            <PR localroot="search" msg="Merge the pr."/>
            <PR localroot="clone" msg="Merge the pr."/>
            
    </A>

Code is: `

public class A {
    @JacksonXmlProperty(localName="Ser")
    @JacksonXmlElementWrapper(useWrapping=false)
    List<Ser> ser;
    @JacksonXmlProperty(localName="PR")
    @JacksonXmlElementWrapper(useWrapping=false)
    List<PR> pR;
    
    \\getters
     \\Setters
    
}

`

For Ser:

public class Ser {
    
    @JacksonXmlProperty(isAttribute=true,localName="name")
    String name;
    @JacksonXmlProperty(isAttribute=true,localName="branch")
    String branch;
    @JacksonXmlProperty(isAttribute=true,localName="localroot")
    String localroot;

\\getter & setters

}

Similar code for PR:

public class PR {
    @JacksonXmlProperty(isAttribute=true,localName="msg")
    String msg;
    @JacksonXmlProperty(isAttribute=true,localName="localroot")
    String localroot;

\\getter & setters

}

Code where reading the file having XML:

public ServiceImpl{
\\hiding other part.

A obj = xmlMapper.readValue(new File(path), A.class);

}

Tried with the latest version as well for jackson-dataformat-xml. Nothing working.

This question is different as here issue is not of wrapping xml.

Upvotes: 0

Views: 27

Answers (0)

Related Questions