I'm parsing a xml into an object using Simple Framework. The problem is that the xml has elements with the same name but in different paths.
XML:
<prestashop>
<products>
<product>
<name>
<language id="1"> name </language>
</name>
<description>
<language id="1"> description </language>
</description>
<description_short>
<language id="1"> desc </language>
</description_short>
</product>
</products>
</prestashop>
my class is mapped like this:
@Root(name="prestashop")
public class Product{
@Element(name="language")
@Path("products/product/description_short[1]")
private String shortDesc;
@Element(name="language")
@Path("products/product/description[1]")
private String longDesc;
@Element(name="language")
@Path("products/product/name[1]")
private String name;
}
But during the deserialization, it gives me the exception:
org.simpleframework.xml.core.PersistenceException:
Element 'language' is already used with @org.simpleframework.xml.Element(data=false, name=language, required=true, type=void)
on field 'name' private java.lang.String model.Product.name at line 8
How can i map tags with the same name but in different paths?
if I serialize the product object it gives me the correct XML structure:
<prestashop xmlns="http://www.w3.org/1999/xlink">
<products>
<product>
<description_short>
<language>short</language>
</description_short>
<id_default_image href="path"/>
<description>
<language>long</language>
</description>
<name>
<language>aaa</language>
</name>
<price>10.0</price>
<id>1</id>
</product>
</products>
</prestashop>
Im deserializing like this:
product = new Product();
InputStream in = res.getResponse();
Serializer serializer = new Persister();
serializer.read(product, in,false);