Bom dia Pessoal,
Eu te juro que procurei muito sobre XStream antes de vir encher o saco de vocês é que eu to batendo cabeça e não consigo terminar a leitura de um XML, cada hora tenho um problema diferente.
Eu preciso ler um XML parecido com este:
<?xml version="1.0" encoding="utf-8"?>
<MigrationEstimationReport>
<UserEstimationList>
<EntityName>[email removido]</EntityName>
<StoreEstimationList>
<StoreName>[email removido]</StoreName>
<EstimationStatus value="Fail" />
<EmailEstimationStatus>
<EstimationStatus value="Fail" />
<StartTime>2011-05-25T18:36:00.000Z</StartTime>
<EndTime>2011-05-25T18:36:05.000Z</EndTime>
</EmailEstimationStatus>
</StoreEstimationList>
</UserEstimationList>
<UserEstimationList>
<EntityName>[email removido]</EntityName>
<StoreEstimationList>
<StoreName>[email removido]</StoreName>
<EstimationStatus value="Fail" />
<EmailEstimationStatus>
<EstimationStatus value="Fail" />
<StartTime>2011-05-25T18:36:05.000Z</StartTime>
<EndTime>2011-05-25T18:36:07.000Z</EndTime>
</EmailEstimationStatus>
</StoreEstimationList>
</UserEstimationList>
<UserEstimationList>
<EntityName>[email removido]</EntityName>
<StoreEstimationList>
<StoreName>[email removido]</StoreName>
<EstimationStatus value="Success" />
<EmailEstimationStatus>
<EstimationStatus value="Success" />
<FolderList>
<FolderName>Itens Enviados</FolderName>
<FolderStatus value="Success" />
<TotalCount value="571" />
</FolderList>
<FolderList>
<FolderName>Lixeira</FolderName>
<FolderStatus value="Success" />
<TotalCount value="3" />
</FolderList>
<TotalCount value="574" />
<StartTime>2011-05-25T18:36:07.000Z</StartTime>
<EndTime>2011-05-25T18:36:12.000Z</EndTime>
</EmailEstimationStatus>
</StoreEstimationList>
</UserEstimationList>
</MigrationEstimationReport>
Para isso refiz TODA hierarquia de classe como eu li para e falaram pra fazer depois fui criar os aliases no meu método que acabou ficando algo assim
public void readXML(String path) throws IOException, ClassNotFoundException {
FileReader fileReader = new FileReader(path);
BufferedReader in = new BufferedReader(fileReader);
XStream stream = new XStream(new DomDriver());
stream.alias("MigrationEstimationReport", MigrationEstimationReport.class);
stream.alias("UserEstimationList", UserEstimationList.class);
stream.alias("EntityName", EntityName.class);
stream.alias("StoreEstimationList", StoreEstimationList.class);
stream.alias("EmailEstimationStatus", EmailEstimationStatus.class);
stream.alias("EstimationStatus", EstimationStatus.class);
stream.alias("StartTime", StartTime.class);
stream.alias("EndTime", EndTime.class);
stream.alias("TotalCount", TotalCount.class);
stream.alias("FolderList", FolderList.class);
List<UserEstimationList> userEstimationList = (List<UserEstimationList>) stream.fromXML(in);
String str;
while((str = in.readLine()) != null){
System.out.println(str);
}
in.close();
//return estimationXML;
}
No começo estava tendo problemas com classes não mapeadas mas agora estou tendo um problema no resultado do UserEstimationList
Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: UserEstimationList
---- Debugging information ----
duplicate-field : UserEstimationList
class : com.gammeestimation.model.MigrationEstimationReport
required-type : com.gammeestimation.model.MigrationEstimationReport
path : /MigrationEstimationReport/UserEstimationList[2]
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$SeenFields.add(AbstractReflectionConverter.java:322)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:234)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:162)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:82)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:63)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:76)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:60)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:137)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:33)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:923)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:909)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:853)
at com.gammeestimation.main.ReadXML.readXML(ReadXML.java:39)
at com.gammeestimation.main.EstimationMain.main(EstimationMain.java:14)
Vou copiar também as classes modelos,
[size=7]public class MigrationEstimationReport {
private List<UserEstimationList> UserEstimationList;
public List<UserEstimationList> getUserEstimationList() {
return UserEstimationList;
}
public void setUserEstimationList(List<UserEstimationList> userEstimationList) {
this.UserEstimationList = userEstimationList;
}
}
public class UserEstimationList {
private List<EntityName> EntityName;
private List<StoreEstimationList> StoreEstimationList;
public List<EntityName> getEntityName() {
return EntityName;
}
public void setEntityName(List<EntityName> entityName) {
EntityName = entityName;
}
public List<StoreEstimationList> getStoreEstimationList() {
return StoreEstimationList;
}
public void setStoreEstimationList(List<StoreEstimationList> storeEstimationList) {
this.StoreEstimationList = storeEstimationList;
}
}
Desculpem por criar um topico tão cheio de código, eu odeio ver topicos assim mas estou sem ideia como resolver.
Obrigado!

