[RESOLVIDO] Como pegar uma lista usando o método GET e Vraptor?  XML
Índice dos Fóruns » Frameworks e Bibliotecas brasileiros
Autor Mensagem
bland
JavaEvangelist

Membro desde: 10/12/2004 09:36:35
Mensagens: 330
Offline

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:



E o controlador:

E então eu tenho a classe de teste...

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:2
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:4
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:3
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:6
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:71)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:8
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:86)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:96)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
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:20
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.

This message was edited 1 time. Last update was at 21/12/2011 08:58:07


http://www.twitter.com/almeidafabiano

Fabiano Almeida.
[MSN]
Lucas Cavalcanti
GUJ Hacker
[Avatar]

Membro desde: 08/07/2007 00:08:14
Mensagens: 6396
Offline

o problema é que o XStream talvez não saiba funcionar bem quando o elemento raiz é uma lista...

se você criar a uma classe no cliente:



e adicionar elas no xmlTypes deve funcionar...

--
Caelum
www.caelum.com.br

bland
JavaEvangelist

Membro desde: 10/12/2004 09:36:35
Mensagens: 330
Offline

Olá Lucas, tudo bem?

Obrigado de antemão.

Fiz o que você recomendou e passou a dar outro erro:

com.thoughtworks.xstream.converters.ConversionException: idServico : idServico : idServico : idServico
---- Debugging information ----
message : idServico : idServico
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : idServico : idServico
class : br.com.scmba.servico.lancamento.item.conta.genhio.dto.Servicos
required-type : java.util.ArrayList
path : /servicos/servicoCobertoDto/idServico
line number : 3
-------------------------------
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.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:246)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:21
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.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:3
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:2
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:4
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:3
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: idServico : idServico
at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:6
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:71)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:8
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:86)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:96)
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:3
at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:52)
at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29)
at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:70)
at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:6
at com.thoughtworks.xstream.converters.collections.CollectionConverter.unmarshal(CollectionConverter.java:61)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:82)
... 42 more

Criei a classe Servicos e adicionei aos testes:

Tentei seguir a sua lógica (criar um novo objeto com o nome Servicos) para tentar resolver esse erro e não consegui.
Sabe dizer o que estou fazendo de errado?

Obrigado.

http://www.twitter.com/almeidafabiano

Fabiano Almeida.
[MSN]
Lucas Cavalcanti
GUJ Hacker
[Avatar]

Membro desde: 08/07/2007 00:08:14
Mensagens: 6396
Offline

como está sendo gerado o xml? posta aqui um exemplo por favor.

--
Caelum
www.caelum.com.br

bland
JavaEvangelist

Membro desde: 10/12/2004 09:36:35
Mensagens: 330
Offline

Lucas,

Segue um exemplo do arquivo de retorno.

Pelo erro apresentado e a maneira como o XML está sendo gerado, penso que o erro está na geração do arquivo. Ou seja, ele deveria estar informando que o servicoCobertoDto faz parte de uma lista.

Será que o erro estaria aqui?

http://www.twitter.com/almeidafabiano

Fabiano Almeida.
[MSN]
Lucas Cavalcanti
GUJ Hacker
[Avatar]

Membro desde: 08/07/2007 00:08:14
Mensagens: 6396
Offline

Tenta o seguinte, na classe Servicos:


--
Caelum
www.caelum.com.br

bland
JavaEvangelist

Membro desde: 10/12/2004 09:36:35
Mensagens: 330
Offline

Lucas,

Funcionou! A sua sugestão de mudança deu certo, porém eu precisei mudar isso nos meus testes:

Ou seja, ao invés de retornar uma lista de ServicosCobertosDto, ele retorna um objeto Servicos com a lista dentro.

Muito obrigado pela sua ajuda.

Abraço!

http://www.twitter.com/almeidafabiano

Fabiano Almeida.
[MSN]
 
Índice dos Fóruns » Frameworks e Bibliotecas brasileiros
Ir para:   
Powered by JForum 2.1.8 © JForum Team