javaxmlsimple-frameworksimple-xml-converter

Issue mapping xml to java using simplexml 2.1.0


I am trying to map a xml response given by a web service to a java object using SimpleXML 2.1.0, but i am stuck.

This is the xml:

<QueryINVAP-WS-ASSETResponse baseLanguage="ES" creationDateTime="2016-11-08T17:10:09-03:00">
<INVAP-WS-ASSETSet>
    <ASSET rowstamp="265381811">
        <ASSETID>1529</ASSETID>
        <ASSETNUM>2503</ASSETNUM>
        <DESCRIPTION>POWER CHASSIS()</DESCRIPTION>
        <ITEMNUM>A000232</ITEMNUM>
        <LOCATION>LOCATIONTEST</LOCATION>
        <SERIALNUM>123456789</SERIALNUM>
        <SITEID>TVD</SITEID>
    </ASSET>
</INVAP-WS-ASSETSet>

As you can imagine, the only data I want to convert to a java object are assetid, assetnum, description, itemnum, location, SerialNum and siteid.

Until now this is what I have:

@Root(name = "QueryINVAP-WS-ASSETResponse", strict = false)
public class Activos {

    @ElementList(inline = true, entry = "ASSET", type = Activo.class)
    private List<Activo> activos;

    @Root
    class Activo {

        @Attribute(name = "rowstamp")
        public String rowstamp;

        @Element(name = "ASSETID")
        public Integer assetid;

        @Element(name = "ASSETNUM")
        public String assetnum;

        @Element(name = "DESCRIPTION")
        public String description;

        @Element(name = "LOCATION")
        public String location;

        @Element(name = "SERIALNUM")
        public String serialnum;

        @Element(name = "SITEID")
        public String siteid;
    }
}

The error I get is:

org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=ASSET, inline=true, name=, required=true, type=class invap.invapgestionmovil.modelos.Activos$Activo) on field 'activos' private java.util.List invap.invapgestionmovil.modelos.Activos.activos for class invap.invapgestionmovil.modelos.Activos at line 1

what am I doing wrong?


Solution

  • Well, finally I solved the issue. I created three classes:

    @Root(name = "QueryINVAP-WS-ASSETResponse", strict=false)
    public class QueryINVAPWSASSETResponse {
    
        @Element(name = "INVAP-WS-ASSETSet")
        private INVAPWSASSETSet set;
    }
    

    @Root(name = "INVAP-WS-ASSETSet", strict=false)
    public class INVAPWSASSETSet {
    
        @ElementList(inline=true, name = "ASSET")
        private List<Activo> activos;
    }
    

    @Root(name = "ASSET", strict = false)
    public class Activo {
    
        @Attribute(name = "rowstamp")
        public String rowstamp;
    
        @Element(name = "ASSETID")
        public Integer assetid;
    
        @Element(name = "ASSETNUM")
        public String assetnum;
    
        @Element(name = "DESCRIPTION")
        public String description;
    
        @Element(name = "LOCATION")
        public String location;
    
        @Element(name = "SERIALNUM")
        public String serialnum;
    
        @Element(name = "SITEID")
        public String siteid;
    
    }
    

    Now when I do the call I get the asset "wrapped" with the others two classes.

    Hope this help others :) Regards