Hi,

Daniel Gomes-THINK IT wrote:

>  
> 
> Hi,
> 
>  
> 
> I have one xml that one field is an array, but sometimes is returned one
> message and I get the exception
> com.thoughtworks.xstream.mapper.CannotResolveClassException.
> 
>  
> 
> Exemplo:
> 
> First case:
> 
> ...
> 
>                 <CONSIGNACOES>
> 
>                                <CONSIGNACAO id="1">
> 

[snip]

> 
>                                </CONSIGNACAO>
> 
>                 </CONSIGNACOES>
> 
> ...
> 
> Second case:
> 
> ...
> 
> <CONSIGNACOES>
> 
>        <MSG_CONSIGNACOES>NAO EXISTE CONSIGNACOES ATIVAS PARA ESTE
>        BENEFICIO</MSG_CONSIGNACOES>
> 
>    </CONSIGNACOES>
> 
> ...
> 
>  
> 
> Here is my class:
> 
>  
> 
> public class CONSIGNACOES {
> 
>  
> 
>     private String SITUACAO;
> 

[snip]

>  
> 
>     private String MSG_CONSIGNACOES;
> 
> ...
> 
> }
> 
>  
> 
> Alias
> 
> procxml.setAlias("CONSULTA", CONSULTA.class);
> 
>             procxml.setAlias("INFORMACOES_BENEFICIO",
>             INFORMACOES_BENEFICIO.class);
> 
>             procxml.setAlias("RUBRICA", RUBRICA.class);
> 
>             procxml.setAlias("DETALHAMENTO", DETALHAMENTO.class);
> 
>             procxml.setAlias("CONSIGNACÔES", CONSIGNACAO.class);
> 
>  
> 
> So , how I can do the convert ?
> 
>  
> 
> This is the message error:
> 
>  
> 
> com.thoughtworks.xstream.mapper.CannotResolveClassException:
> MSG_CONSIGNACOES

[snip]

> Caused: com.thoughtworks.xstream.converters.ConversionException:
> MSG_CONSIGNACOES : MSG_CONSIGNACOES
> 
> ---- Debugging information ----
> 
> message             : MSG_CONSIGNACOES
> 
> cause-exception     :
> com.thoughtworks.xstream.mapper.CannotResolveClassException
> 
> cause-message       : MSG_CONSIGNACOES
> 
> class               : java.util.ArrayList
> 
> required-type       : java.util.ArrayList
> 
> converter-type      :
> com.thoughtworks.xstream.converters.collections.CollectionConverter
> 
> path                : /CONSULTA/CONSIGNACOES/MSG_CONSIGNACOES
> 
> line number         : 64
> 
> class[1]            : br.com.thinkit.res.dias.CONSULTA
> 
> converter-type[1]   :
> com.thoughtworks.xstream.converters.reflection.ReflectionConverter
> 
> version             : null


You did not post your container class (CONSULTA.class), but I assume that 
you have simply declared a field with a List (it cannot be an array, as you 
have claimed, because XStream is using a CollectionConverter and want to 
create an ArrayList). Elements of collections are represented in XML with a 
tag that represents a class type (either directly or using a type alias), 
but "MSG_CONSIGNACOES" is neither. XStream is informing you in detail about 
this fact in the exception.

Since the XML represents for XStream an object graph, you should not be 
surprised that if you provide a different XML structure, that XStream also 
expects a different object model.

For such special cases as yours you will always have to use own custom 
converters. Simply derive from the CollectionConverter, overload 
"addCurrentElementToCollection" and do what you have to do, if the name of 
the current tag is "MSG_CONSIGNACOES". You may register it as local 
converter for your field with the list.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to