Pessoal, estou recebendo erro ao tentar deserializar o XML abaixo utilizando XStream 1.22.
Na estrutura abaixo existem N “LINHA” dentro de FPATIVO. Parece dar erro assim que carrega a segunda linha, porém tenho um List para receber estas linhas. Alguma idéia?
DFPATIVO.xml
<DFPATIVO.DB>
<LINHA CODCVM="018821" DATADFP="31/12/2006" TIPO_DOC="2" CODCONTA="1" DESCONTA="Ativo Total" VALOR3="1768285" VALOR2="1593258" VALOR1="1217927" OBRIGATORI="True" TIPO_INF="C" />
<LINHA CODCVM="018821" DATADFP="31/12/2006" TIPO_DOC="2" CODCONTA="1.01" DESCONTA="Ativo Circulante" VALOR3="497383" VALOR2="229043" VALOR1="455321" OBRIGATORI="True" TIPO_INF="C" />
...
</DFPATIVO.DB>
Dfpativo:
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("DFPATIVO.DB")
public class DfpAtivo
{
@XStreamAlias("LINHA")
List<Linha> linha = new ArrayList<Linha>();
//getters e setters
}
Linha:
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("LINHA")
public class Linha
{
@XStreamAlias("CODCVM")
private String codcvm;
@XStreamAlias("DATADFP")
private String dataDfp;
@XStreamAlias("TIPO_DOC")
private String tipodoc;
@XStreamAlias("CODCONTA")
private String codconta;
@XStreamAlias("DESCCONTA")
private String descconta;
@XStreamAlias("VALOR3")
private String valor3;
@XStreamAlias("VALOR2")
private String valor2;
@XStreamAlias("VALOR1")
private String valor1;
@XStreamAlias("OBRIGATORI")
private String obrigatori;
@XStreamAlias("TIPO_INF")
private String tipo_inf;
//getters e setters
}
Chamada:
XStream xstream = new XStream();
Annotations.configureAliases(xstream, DfpAtivo.class,Linha.class);
DfpAtivo dfp = (DfpAtivo) xstream.fromXML(xml);
Recebo o seguinte erro:
[code]Exception in thread “main” com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: linha
---- Debugging information ----
duplicate-field : linha
class : DfpAtivo
required-type : DfpAtivo
path : /DFPATIVO.DB/LINHA[2]
line number : 4
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$SeenFields.add(AbstractReflectionConverter.java:271)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:204)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:125)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:846)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:833)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:789)
at Teste.main(Teste.java:18)
[/code]