Olá pessoal,
Eu estou tentando recuperar uma lista de itens de um determinado objeto, mas sempre dá erro no parse do Xstream. Tentei diversas opções com base nesses arquivos de exemplo e mesmo assim, nada. Me senti confuso seguindo esses arquivos, pra falar a verdade.
Tenho a seguinte configuração:
@ Component
public class CustomXStreamXMLDeserializer extends XStreamXMLDeserializer {
public CustomXStreamXMLDeserializer ( ParameterNameProvider provider ) {
super ( provider );
}
@ Override
protected XStream getXStream () {
XStream stream = super . getXStream ();
stream . processAnnotations ( new Class [] { ServicoCobertoDto . class , ServicoItemCobrancaDto . class } );
return stream ;
}
}
@XStreamAlias ( "servicoItemCobranca" )
public class ServicoItemCobrancaDto {
private List & lt ; ServicoCobertoDto & gt ; servicoCoberto ;
public List & lt ; ServicoCobertoDto & gt ; getServicoCoberto () {
return servicoCoberto ;
}
public void setServicoCoberto ( List & lt ; ServicoCobertoDto & gt ; servicoCoberto ) {
this . servicoCoberto = servicoCoberto ;
}
}
@XStreamAlias ( "servicoCoberto" )
public class ServicoCobertoDto {
private Long idServico ;
public Long getIdServico () {
return idServico ;
}
public void setIdServico ( Long idServico ) {
this . idServico = idServico ;
}
}
E o controlador:
@Resource
public class GerirServicoController {
private Result result ;
public GerirServicoController ( Result result ) {
this . result = result ;
}
@Get
@Path ( "/servicosCobertos/{id}" )
public void servicosCobertos ( Long id ) {
try {
if ( id != null ) {
// Processamento ...
result . use ( Results . representation () ). from ( servicoItemCobrancaDto . getServicoCoberto (), "servicos" ). serialize ();
} else {
throw new IllegalArgumentException ( "Exception text" );
}
} catch ( Exception ex ) {
result . use ( Results . status () ). badRequest ( ex . getMessage () );
}
}
}
E então eu tenho a classe de teste…
public class ServicoItemCobrancaTest {
private static final String XML = "application/xml" ;
private RestClient restfulie ;
@Before
public void setUp () throws Exception {
restfulie = Restfulie . custom ();
restfulie . getMediaTypes (). register ( new XmlMediaType (). withTypes ( ServicoItemCobrancaDto . class , ServicoCobertoDto . class ) );
}
@Test
public void shouldBeAbleToNavigateThroughLinks () throws Exception {
Response response = restfulie . at ( "http://localhost:8080/genhio/servicosCobertos/1" ). accept ( XML ). get ();
List & lt ; ServicoCobertoDto & gt ; servicos = response . getResource ();
// ...
}
}
Só que no ponto que eu tento pegar o resource (response.getResource()) está dando o seguinte erro:
com.thoughtworks.xstream.converters.ConversionException: servicoCobertoDto : servicoCobertoDto : servicoCobertoDto : servicoCobertoDto
---- Debugging information ----
message : servicoCobertoDto : servicoCobertoDto
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : servicoCobertoDto : servicoCobertoDto
class : br.com.scmba.servico.lancamento.item.conta.genhio.dto.ServicoCobertoDto
required-type : br.com.scmba.servico.lancamento.item.conta.genhio.dto.ServicoCobertoDto
path : /servicos/servicoCobertoDto
line number : 2
at com . thoughtworks . xstream . core . TreeUnmarshaller . convert ( TreeUnmarshaller . java : 89 )
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 . thoughtworks . xstream . XStream . fromXML ( XStream . java : 845 )
at br . com . caelum . restfulie . mediatype . XmlMediaType . unmarshal ( XmlMediaType . java : 73 )
at br . com . caelum . restfulie . http . apache . ApacheResponse . getResource ( ApacheResponse . java : 60 )
at br . com . scmba . servico . lancamento . item . conta . util . ServicoItemCobrancaTest . shouldBeAbleToNavigateThroughLinks ( ServicoItemCobrancaTest . java : 37 )
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( NativeMethodAccessorImpl . java : 39 )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( DelegatingMethodAccessorImpl . java : 25 )
at java . lang . reflect . Method . invoke ( Method . java : 597 )
at org . junit . runners . model . FrameworkMethod $ 1 . runReflectiveCall ( FrameworkMethod . java : 44 )
at org . junit . internal . runners . model . ReflectiveCallable . run ( ReflectiveCallable . java : 15 )
at org . junit . runners . model . FrameworkMethod . invokeExplosively ( FrameworkMethod . java : 41 )
at org . junit . internal . runners . statements . InvokeMethod . evaluate ( InvokeMethod . java : 20 )
at org . junit . internal . runners . statements . RunBefores . evaluate ( RunBefores . java : 28 )
at org . junit . runners . ParentRunner . runLeaf ( ParentRunner . java : 263 )
at org . junit . runners . BlockJUnit4ClassRunner . runChild ( BlockJUnit4ClassRunner . java : 69 )
at org . junit . runners . BlockJUnit4ClassRunner . runChild ( BlockJUnit4ClassRunner . java : 48 )
at org . junit . runners . ParentRunner $ 3 . run ( ParentRunner . java : 231 )
at org . junit . runners . ParentRunner $ 1 . schedule ( ParentRunner . java : 60 )
at org . junit . runners . ParentRunner . runChildren ( ParentRunner . java : 229 )
at org . junit . runners . ParentRunner . access $ 000 ( ParentRunner . java : 50 )
at org . junit . runners . ParentRunner $ 2 . evaluate ( ParentRunner . java : 222 )
at org . junit . runners . ParentRunner . run ( ParentRunner . java : 292 )
at org . eclipse . jdt . internal . junit4 . runner . JUnit4TestReference . run ( JUnit4TestReference . java : 49 )
at org . eclipse . jdt . internal . junit . runner . TestExecution . run ( TestExecution . java : 38 )
at org . eclipse . jdt . internal . junit . runner . RemoteTestRunner . runTests ( RemoteTestRunner . java : 467 )
at org . eclipse . jdt . internal . junit . runner . RemoteTestRunner . runTests ( RemoteTestRunner . java : 683 )
at org . eclipse . jdt . internal . junit . runner . RemoteTestRunner . run ( RemoteTestRunner . java : 390 )
at org . eclipse . jdt . internal . junit . runner . RemoteTestRunner . main ( RemoteTestRunner . java : 197 )
Caused by: com.thoughtworks.xstream.mapper.CannotResolveClassException: servicoCobertoDto : servicoCobertoDto
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:68)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:71)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:86)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:96)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:52)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:347)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:208)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:162)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:82)
… 36 more
Como poderia resolver esse problema? Alguém tem alguma sugestão?
De antemão, obrigado.