Consumir JSON.

430 views
Skip to first unread message

Dev.Softhouse

unread,
Apr 10, 2012, 2:07:46 PM4/10/12
to caelum-...@googlegroups.com
 Boa tarde pessoal, 
 
 Estou tentando consumir um JSON vindo de um form via POST:

{"bairro":{"id":"","nome":"ttetretretet","nomeAbreviado":"tetrtrtertertre","cidade.id":350580,"cidade.nome":"","cidade.estado.sigla":"","cidade.estado.pais.nomePais":""}}

Minha classe de modelo é um Bairro:
@XStreamAlias("bairro")
@Entity
@Table(name="tb_bairro_cidade")
public class Bairro {
private String id;
private Cidade cidade;
private String nome;
private String nomeAbreviado;
........

Já no controller deixei assim:
@Consumes //também tentei passando o parametro application/json
@Post("/bairros")
public void save(Bairro bairro){
this.validator.validate(bairro);
this.validator.onErrorSendBadRequest();
//valida regra de negócio
//persiste no banco
result.use(json()).from("Bairro cadastrado com sucesso","message").serialize();
result.nothing();
..................

Eu estou utilizando a classe que o Eric fez para tratar a desserialização:
@Component
@Deserializes({"application/json", "json", "text/javascript"})
public class CustomJSONDeserializer extends JsonDeserializer {

public CustomJSONDeserializer(ParameterNameProvider provider,
TypeNameExtractor extractor) {
super(provider, extractor);
}

public XStream getConfiguredXStream(java.lang.reflect.Method javaMethod,
java.lang.Class<?>[] types) {
XStream xStream = super.getConfiguredXStream(javaMethod, types);

for (Type type : javaMethod.getGenericParameterTypes()) {
if (type instanceof ParameterizedType)
xStream.processAnnotations((Class<?>) ((ParameterizedType) type)
.getActualTypeArguments()[0]);
}
xStream.processAnnotations(types);

return xStream;
}
}


Quando eu dou um POST ele retorna um erro 500 e exibe esse erro no console (mesmo eu tendo anotado com @XStreamAlias("cidade") @XStreamAlias("estado") @XStreamAlias("pais") ):
Estou usando a versão 3.4 do vraptor + Iogi para evitar que o parametros vazios sejam setados para "".
 
14:37:33,137 DEBUG [IogiParametersProvider] IogiParametersProvider is up
14:37:33,140 DEBUG [LazyInterceptorHandler] Invoking interceptor ParametersInstantiatorInterceptor
14:37:33,140 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for BairroController.save(Bairro) as [bairro]
14:37:33,140 DEBUG [IogiParametersProvider] getParametersFor() called with parameters Parameters(Parameter(total -> total), Parameter(_dc -> 1334079453101)) and targets [Target(name=bairro, type=class br.com.softhouse.siseduca.model.Bairro)].
14:37:33,142 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for Bairro() as []
14:37:33,153 DEBUG [ParametersInstantiatorInterceptor] Parameter values for [DefaultResourceMethod: BairroController.saveBairroController.save(Bairro)] are [Bairro [nome=null]]
14:37:33,172 DEBUG [LazyInterceptorHandler] Invoking interceptor DeserializingInterceptor
14:37:33,187 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for BairroController.save(Bairro) as [bairro]
10/04/2012 14:37:33 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [default] in context with path [/siseduca] threw exception
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field br.com.model.Bairro.cidade.id
---- Debugging information ----
field               : cidade.id
class               : br.com.softhouse.siseduca.model.Bairro
required-type       : br.com.softhouse.siseduca.model.Bairro
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number         : -1
version             : null
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:453)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:294)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1052)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1036)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:921)
at br.com.caelum.vraptor.deserialization.JsonDeserializer.deserialize(JsonDeserializer.java:39)
at br.com.caelum.vraptor.interceptor.DeserializingInterceptor.intercept(DeserializingInterceptor.java:87)
at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:59)

Lucas Cavalcanti

unread,
Apr 10, 2012, 2:36:40 PM4/10/12
to caelum-...@googlegroups.com
vc mandou uma request com json e mesmo assim passou pelo iogi?

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/VK8ZUmtVh9cJ.
To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

Dev.Softhouse

unread,
Apr 10, 2012, 2:49:35 PM4/10/12
to caelum-...@googlegroups.com
Lucas ele apareceu no log mas acho que não foi usado, porque logo em seguida apareceu:
DEBUG [LazyInterceptorHandler] Invoking interceptor ParametersInstantiatorInterceptor

Agora depois que desabilitei o Iogi continua o problema: 

15:49:11,871 DEBUG [LazyInterceptorHandler] Invoking interceptor ParametersInstantiatorInterceptor
15:49:11,872 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for BairroController.save(Bairro) as [bairro]
15:49:11,891 DEBUG [ParametersInstantiatorInterceptor] Parameter values for [DefaultResourceMethod: BairroController.saveBairroController.save(Bairro)] are [null]
15:49:11,934 DEBUG [LazyInterceptorHandler] Invoking interceptor DeserializingInterceptor
15:49:11,974 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for BairroController.save(Bairro) as [bairro]
10/04/2012 15:49:12 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [default] in context with path [/siseduca] threw exception
com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field br.com.softhouse.siseduca.model.Bairro.cidade.id
---- Debugging information ----
field               : cidade.id
class               : br.com.model.Bairro
required-type       : br.com.model.Bairro
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
line number         : -1
version             : null
-------------------------------

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.

Lucas Cavalcanti

unread,
Apr 10, 2012, 3:14:17 PM4/10/12
to caelum-...@googlegroups.com
mas o bairro tem esse campo?

aparentemente o json tá vindo com algo assim:

{.... "cidade.id": 3 }

quando era pra vir
 {..... "cidade": { "id": 3} }

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/0cU8c531SbMJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Dev.Softhouse

unread,
Apr 10, 2012, 3:43:48 PM4/10/12
to caelum-...@googlegroups.com
Então, não tem, esse campo já pertence ao objeto cidade então estou fazendo certo na parte do Java? só preciso ver como corrigir isso no front-end?
Só mais uma coisa, eu estou criando alias para o Xstream desserializar os objetos e quando eu tiver que me referenciar ao mesmo objeto por alias diferentes tipo
se eu tiver no mesmo for uma cidadeNatal e uma cidadeAtual por exemplo?
Do jeito tradicional ele se guia pelo nome que dou para a instancia e nesse caso que estou fazendo agora como fica isso?
Obrigado.

Lucas Cavalcanti

unread,
Apr 10, 2012, 4:19:14 PM4/10/12
to caelum-...@googlegroups.com
ele geralmente usa o alias da classe só pro objeto raiz, a partir daí é via nomes dos atributos

2012/4/10 Dev.Softhouse <sup...@softhouse.inf.br>
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/T8_D8OyXAxMJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Davi da Silva Nogueira

unread,
Apr 12, 2012, 1:46:32 PM4/12/12
to caelum-...@googlegroups.com
Galera, estou tendo um problema parecido, ao consumir json. Tenho o seguinte codigo:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>VRaptor Blank Project</title>

<script type="text/javascript">
$(function(){
var uri = "${linkTo[IndexController].post}";

var data = {pessoa : {nome : "Davi", idade : "27"}};
$('button').click(function(){
$.ajax({
 type : "POST",
 url : uri,
 data : data,
 contentType: "application/json",
 success: function(rs) {
   console.log('sucesso');
 }
});
console.log(data);
});
});

</script>

</head>
<body>
<button>Enviar</button>
</body>
</html>

Esta dando erro que não esta conseguindo fazer o parse para json do lado do servidor, e vendo no firebug a informação que esta sendo enviada é:

pessoa%5Bnome%5D=Davi&pessoa%5Bidade%5D=27

No servidor eu tenho um metodo simples somente para testar:

        @Consumes
@Post("/post")
public void post(Pessoa pessoa){
System.out.println(pessoa.getNome());
result.nothing();
}

Alguém sabe alguma coisa sobre isso, o que mais eu deveria estar fazendo?

Lucas Cavalcanti

unread,
Apr 12, 2012, 2:02:28 PM4/12/12
to caelum-...@googlegroups.com
acho que o $.ajax não vai postar um json, pelo menos não desse jeito

2012/4/12 Davi da Silva Nogueira <davi...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/jSKXPcVEHScJ.

Davi da Silva Nogueira

unread,
Apr 12, 2012, 7:16:37 PM4/12/12
to caelum-...@googlegroups.com
Resolvido:
Restfulie.at(uri).as("application/json").post(data);

Suporte

unread,
Apr 26, 2012, 8:26:13 AM4/26/12
to caelum-...@googlegroups.com

Bom dia pessoal.

 

Ainda estou tendo problema para consumir JSON, eu mudei o formato dos dados, mas mesmo assim continua dando problema. (Eu estou usando a versão 3.4.1 do VRaptor e também uma classe componente que peguei aqui na lista que lê o XStreamAlias para fazer a instanciação dos parametros).

 

Cabeçalho de resposta após fazer o post (no front-end setei para ele enviar o content-type application/json):

 

Cabeçalhos de Resposta

Connection       close

Content-Type    text/html;charset=utf-8

Date     Thu, 26 Apr 2012 11:59:31 GMT

Server   Apache-Coyote/1.1

Transfer-Encoding         chunked

Cabeçalhos de Solicitação

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Encoding           gzip, deflate

Accept-Language          pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3

Connection       keep-alive

Content-Length  188

Content-Type   application/json; charset=UTF-8

Cookie  JSESSIONID=DD19DF2F750C488763B11BF383525503

Host     localhost:8080

Referer  http://localhost:8080/sistema/index

User-Agent       Mozilla/5.0 (X11; Linux i686; rv:11.0) Gecko/20100101 Firefox/11.0

X-Requested-With         XMLHttpRequest

 

No fire bug tem a aba postar que mostra o que estou enviando no post (esse JSON aqui está formatado para facilitar a leitura, mas no post do navegador ele manda sem formatação):

 

{

  "bairro": {

    "id": "",

    "nome": "sdffsdfdds",

    "nomeAbreviado": "fdsffddfdfdsfdsfsd",

    "cidade": {

      "id": 420005,

      "nome": "ABDON BATISTA",

      "estado": {

        "id": 42,

        "sigla": "SC",

        "pais": {

          "id": 10,

          "nome": "BRASIL"

        }

      }

    }

  }

}

 

No final o Vraptor lança a exception:

08:59:31,732 DEBUG [VRaptor             ] VRaptor received a new request

08:59:31,751 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ResourceLookupInterceptor

08:59:31,751 DEBUG [DefaultResourceTranslator] trying to access /bairros

08:59:31,751 DEBUG [DefaultResourceTranslator] found resource [DefaultResourceMethod: BairroController.saveBairroController.save(Bairro)]

08:59:31,753 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExceptionHandlerInterceptor

08:59:31,753 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor InstantiateInterceptor

08:59:31,757 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor FlashInterceptor

08:59:31,761 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor HibernateTransactionInterceptor

08:59:31,766 DEBUG [LazyInterceptorHandler] Invoking interceptor ParametersInstantiatorInterceptor

08:59:31,767 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for BairroController.save(Bairro) as [bairro]

08:59:31,767 DEBUG [ParametersInstantiatorInterceptor] Parameter values for [DefaultResourceMethod: BairroController.saveBairroController.save(Bairro)] are [null]

08:59:31,800 DEBUG [LazyInterceptorHandler] Invoking interceptor DeserializingInterceptor

08:59:31,847 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for BairroController.save(Bairro) as [bairro]

08:59:31,847 DEBUG [XStreamConverters   ] registered Xstream converter forbr.com.caelum.vraptor.validator.MessageConverter

08:59:31,847 DEBUG [XStreamConverters   ] registered Xstream converter forbr.com.caelum.vraptor.serialization.xstream.XStreamConverters$NullConverter

26/04/2012 08:59:31 org.apache.catalina.core.StandardWrapperValve invoke

GRAVE: Servlet.service() for servlet [default] in context with path [/siseduca] threw exception

com.thoughtworks.xstream.converters.ConversionException: null : null

---- Debugging information ----

cause-exception     : java.lang.NullPointerException

cause-message       : null

class               : br.com.dev.sis.model.Bairro

required-type       : br.com.dev.sis.model.Pais

line number         : -1

-------------------------------

            at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:89)

            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:218)

            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.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:218)

            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.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:218)

            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.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:861)

            at br.com.caelum.vraptor.deserialization.JsonDeserializer.deserialize(JsonDeserializer.java:62)

            at br.com.caelum.vraptor.interceptor.DeserializingInterceptor.intercept(DeserializingInterceptor.java:87)

            at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:59)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor.intercept(ParametersInstantiatorInterceptor.java:93)

            at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:59)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.util.hibernate.HibernateTransactionInterceptor.intercept(HibernateTransactionInterceptor.java:48)

            at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:83)

            at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:48)

            at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:71)

            at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:69)

            at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)

            at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)

            at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)

            at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:91)

            at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58)

            at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:88)

            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)

            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)

            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)

            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)

            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)

            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)

            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)

            at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)

            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)

            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)

            at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)

            at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)

            at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)

            at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

            at java.lang.Thread.run(Thread.java:662)

Caused by: java.lang.NullPointerException

            at br.com.caelum.vraptor.serialization.xstream.VRaptorClassMapper.shouldSerializeMember(VRaptorClassMapper.java:55)

            at com.thoughtworks.xstream.mapper.MapperWrapper.shouldSerializeMember(MapperWrapper.java:110)

            at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:342)

            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)

            ... 68 more

 


To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/0cU8c531SbMJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/T8_D8OyXAxMJ.


To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

Lucas Cavalcanti

unread,
Apr 26, 2012, 8:54:47 AM4/26/12
to caelum-...@googlegroups.com
Tenta tirar essa classe que lê o XStreamAlias... a nova versão do vraptor já deveria fazer isso automaticamente.

2012/4/26 Suporte <sup...@softhouse.inf.br>

Suporte

unread,
Apr 26, 2012, 9:23:05 AM4/26/12
to caelum-...@googlegroups.com

Bom dia. Obrigado era isso mesmo, eu tinha feito da outra vez, porém como os dados estavam mal formados não percebi este outro problema....

Nesse processo de consumir o JSON o XStream não usa os setters das classes de modelo? Pergunto por que estou mandando um atributo “id”:” ” com campo em branco (String) daí no setter da classe bairro fiz uma verificação que sele for

Em branco seta para null, mas ele passa direto, imprimi no console os dados do objeto o id está ficando com o valor “ ”, com o IOGI eu usava ele antes para evitar esse problema de setar valores “ ”, no lugar ele sempre setava null.

Lucas Cavalcanti

unread,
Apr 26, 2012, 9:24:02 AM4/26/12
to caelum-...@googlegroups.com
O XStream por padrão seta os atributos diretamente... mas dá pra configurar ele pra sempre usar os setters. Quer fazer isso?

precisa sobrescrever o componente XStreamBuilder (estendendo XStreamBuilderImpl e anotando @Component), e sobrescrever
o método que configura o xstream adicionando o converter JavaBeanConverter (ou algo parecido com isso).

2012/4/26 Suporte <sup...@softhouse.inf.br>

Suporte

unread,
Apr 26, 2012, 9:38:41 AM4/26/12
to caelum-...@googlegroups.com

Opa, então eu to com essa classe aqui que peguei na lista:

Ela remove esses resolves-to da serialização, no caso terei que modificar esse método para usar o JavaBeanCoverter tb?

 

@PrototypeScoped

@Component

public class CustomXStreamBuilder extends XStreamBuilderImpl {

 

public CustomXStreamBuilder(XStreamConverters converters,

                                   TypeNameExtractor extractor) {

                        super(converters, extractor);

            }

 

            // delega o construtor

            public XStream configure(XStream xstream) {

 

                        super.configure(xstream);

 

                        xstream.aliasSystemAttribute(null, "class");

 

                        xstream.aliasSystemAttribute(null, "resolves-to");

 

                        return xstream;

Lucas Cavalcanti

unread,
Apr 26, 2012, 9:39:43 AM4/26/12
to caelum-...@googlegroups.com
isso

2012/4/26 Suporte <sup...@softhouse.inf.br>

Dev.Softhouse

unread,
Apr 26, 2012, 10:22:29 AM4/26/12
to caelum-...@googlegroups.com
Eu tentei assim mas não rolou:

public XStream configure(XStream xstream, JavaBeanConverter beanConverter) {

super.configure(xstream);

xstream.aliasSystemAttribute(null, "class");

xstream.aliasSystemAttribute(null, "resolves-to");
xstream.registerConverter(beanConverter, XStream.PRIORITY_VERY_HIGH);
return xstream;
}

Em quinta-feira, 26 de abril de 2012 10h39min43s UTC-3, Lucas Cavalcanti escreveu:
isso

2012/4/26 Suporte <sup...@softhouse.inf.br>

Opa, então eu to com essa classe aqui que peguei na lista:

Ela remove esses resolves-to da serialização, no caso terei que modificar esse método para usar o JavaBeanCoverter tb?

 

@PrototypeScoped

@Component

public class CustomXStreamBuilder extends XStreamBuilderImpl {

 

public CustomXStreamBuilder(XStreamConverters converters,

                                   TypeNameExtractor extractor) {

                        super(converters, extractor);

            }

 

            // delega o construtor

            public XStream configure(XStream xstream) {

 

                        super.configure(xstream);

 

                        xstream.aliasSystemAttribute(null, "class");

 

                        xstream.aliasSystemAttribute(null, "resolves-to");

 

                        return xstream;

            }

}

De: caelum-vraptor@googlegroups.com [mailto:caelum-vraptor@googlegroups.com] Em nome de Lucas Cavalcanti
Enviada em: quinta-feira, 26 de abril de 2012 10:24
Para: caelum-vraptor@googlegroups.com
Assunto: Re: Consumir JSON.

O XStream por padrão seta os atributos diretamente... mas dá pra configurar ele pra sempre usar os setters. Quer fazer isso?

precisa sobrescrever o componente XStreamBuilder (estendendo XStreamBuilderImpl e anotando @Component), e sobrescrever
o método que configura o xstream adicionando o converter JavaBeanConverter (ou algo parecido com isso).

2012/4/26 Suporte <sup...@softhouse.inf.br>

Bom dia. Obrigado era isso mesmo, eu tinha feito da outra vez, porém como os dados estavam mal formados não percebi este outro problema....

Nesse processo de consumir o JSON o XStream não usa os setters das classes de modelo? Pergunto por que estou mandando um atributo “id”:” ” com campo em branco (String) daí no setter da classe bairro fiz uma verificação que sele for

Em branco seta para null, mas ele passa direto, imprimi no console os dados do objeto o id está ficando com o valor “ ”, com o IOGI eu usava ele antes para evitar esse problema de setar valores “ ”, no lugar ele sempre setava null.

 

De: caelum-vraptor@googlegroups.com [mailto:caelum-vraptor@googlegroups.com] Em nome de Lucas Cavalcanti
Enviada em: quinta-feira, 26 de abril de 2012 09:55


Para: caelum-vraptor@googlegroups.com
Assunto: Re: Consumir JSON.

 

2012/4/26 Suporte <sup...@softhouse.inf.br>

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/0cU8c531SbMJ.


To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/T8_D8OyXAxMJ.


To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.

Jose Maria de Oliveira

unread,
Apr 26, 2012, 10:32:17 AM4/26/12
to caelum-...@googlegroups.com

Pessoal, bom dia.

 

Como obtenho a classe RequestInfo no meu controller?

 

Obrigado

 

Abs

 

 

José Maria de Oliveira

Eccox Technology

Tel.: + 55 11 4133-1969

Fax: + 55 11 4133-1960

jose.o...@eccox.com.br

www.eccox.com.br

Al. Rio Negro, 433, 4º andar, Edifício I

Alphaville, São Paulo, Brasil - CEP: 06454-904

 

"Seus negócios, disponíveis a qualquer momento, em qualquer lugar"

 

Antes de imprimir, pense no compromisso com o Meio Ambiente.

 

Carlos Alberto Junior

unread,
Apr 26, 2012, 10:32:40 AM4/26/12
to caelum-...@googlegroups.com
Se é um recurso do VRaptor só receba ele no construtor....

private RequestInfo info;

public SuaController(RequestInfo info){
....
}


Atenciosamente,
Carlos Alberto Junior Spohr Poletto





--

Jose Maria de Oliveira

unread,
Apr 26, 2012, 10:36:16 AM4/26/12
to caelum-...@googlegroups.com

Tudo bem Carlos?

 

É uma classe do vraptor, mas não está anotada com @Component. Mesmo assim será injetada?

Carlos Alberto Junior

unread,
Apr 26, 2012, 10:37:47 AM4/26/12
to caelum-...@googlegroups.com
Acredito que sim José, 

Senão me engano usei uma classe com um nome parecido uma vez de dentro de um interceptor, mas faça um teste ai.


Atenciosamente,
Carlos Alberto Junior Spohr Poletto



Jose Maria de Oliveira

unread,
Apr 26, 2012, 10:40:52 AM4/26/12
to caelum-...@googlegroups.com

Vlw.

 

Vou testar aqui.

 

Abs

 

José Maria de Oliveira

Eccox Technology

Tel.: + 55 11 4133-1969

Fax: + 55 11 4133-1960

jose.o...@eccox.com.br

www.eccox.com.br

Al. Rio Negro, 433, 4º andar, Edifício I

Alphaville, São Paulo, Brasil - CEP: 06454-904

 

"Seus negócios, disponíveis a qualquer momento, em qualquer lugar"

 

Antes de imprimir, pense no compromisso com o Meio Ambiente.

 

 

De: caelum-...@googlegroups.com [mailto:caelum-...@googlegroups.com] Em nome de Carlos Alberto Junior
Enviada em: quinta-feira, 26 de abril de 2012 11:38
Para: caelum-...@googlegroups.com
Assunto: Re: RequestInfo

 

Acredito que sim José, 

--

Lucas Cavalcanti

unread,
Apr 26, 2012, 10:43:37 AM4/26/12
to caelum-...@googlegroups.com
não é pra receber no parâmetro:


@Override

public XStream configure(XStream xstream) {

super.configure(xstream);

xstream.aliasSystemAttribute(null, "class");

xstream.aliasSystemAttribute(null, "resolves-to");
xstream.registerConverter(new JavaBeanConverter(), XStream.PRIORITY_VERY_HIGH);
return xstream;
}



2012/4/26 Dev.Softhouse <sup...@softhouse.inf.br>
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/LvtN0lSNv70J.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Dev.Softhouse

unread,
Apr 26, 2012, 10:54:16 AM4/26/12
to caelum-...@googlegroups.com
No meu aqui ele pede para passar um Maper, o JavaBeanConverter não tem esse construtor vazio.
new JavaBeanConverter()//Pede um Maper

Lucas Cavalcanti

unread,
Apr 26, 2012, 10:57:40 AM4/26/12
to caelum-...@googlegroups.com
xstream.getMapper();

2012/4/26 Dev.Softhouse <sup...@softhouse.inf.br>
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/tbU9lIgiEhwJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Dev.Softhouse

unread,
Apr 26, 2012, 11:06:50 AM4/26/12
to caelum-...@googlegroups.com
Ele gera esse erro:

GRAVE: Exception starting filter vraptor
java.lang.ExceptionInInitializerError
at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:73)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:42)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:108)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:279)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:252)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:265)
at br.com.caelum.vraptor.VRaptor.<clinit>(VRaptor.java:60)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:125)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:256)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:103)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4624)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5281)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalStateException: Detected both jcl-over-slf4j.jar AND slf4j-jcl.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#jclDelegationLoop for more details.
at org.slf4j.impl.JCLLoggerFactory.<clinit>(JCLLoggerFactory.java:55)
... 28 more
26/04/2012 12:07:52 org.apache.catalina.core.StandardContext startInternal

Lucas Cavalcanti

unread,
Apr 26, 2012, 11:22:42 AM4/26/12
to caelum-...@googlegroups.com
Detected both jcl-over-slf4j.jar AND slf4j-jcl.jar on the class path,

se estiverem os dois no seu classpath, tente tirar um.

2012/4/26 Dev.Softhouse <sup...@softhouse.inf.br>
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/G7qw6XK-insJ.
To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Dev.Softhouse

unread,
Apr 26, 2012, 11:28:21 AM4/26/12
to caelum-...@googlegroups.com
Tava dentro do lib do tomcat, então ele rá rodando agora, porém ao serializar um wrapper para a lista de dados só os atributos simples estão vindo, as collections não.

Lucas Cavalcanti

unread,
Apr 26, 2012, 11:43:28 AM4/26/12
to caelum-...@googlegroups.com
sim, esse é o comportamento padrão do VRaptor.

se quer serializar as collections, vc precisa dar include, ou usar o recursive()

2012/4/26 Dev.Softhouse <sup...@softhouse.inf.br>
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/KM0KrcCAUXUJ.
To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Otávio Garcia

unread,
Apr 26, 2012, 11:46:53 AM4/26/12
to caelum-...@googlegroups.com
Os componentes internos do vraptor são injetados independente de terem o @Component. Até porque o RequestInfo é apenas uma interface, ela não poderia ter um @Component (quem tem é a implementação).

2012/4/26 Jose Maria de Oliveira <jose.O...@eccox.com.br>

Jose Maria de Oliveira

unread,
Apr 26, 2012, 12:02:53 PM4/26/12
to caelum-...@googlegroups.com

Tudo bem Otávio?

 

Injetei o RequestInfo e consegui as informações que preciso, mas é uma classe e não uma interface.

 

package br.com.caelum.vraptor.core;

 

import javax.servlet.FilterChain;

import javax.servlet.ServletContext;

 

import br.com.caelum.vraptor.http.MutableRequest;

import br.com.caelum.vraptor.http.MutableResponse;

 

/**

 * Simple wrapper for request, response and servlet context.

 *

 * @author Fabio Kung

 * @author Guilherme Silveira

 */

public class RequestInfo {

                private final ServletContext servletContext;

 

                private final MutableRequest request;

 

                private final MutableResponse response;

 

...

...

...

...

Dev.Softhouse

unread,
Apr 26, 2012, 12:07:48 PM4/26/12
to caelum-...@googlegroups.com
O meu já está assim com o recursive(), uma coisa que percebi foi que quando eu mudo o parametro XStream.PRIORITY_VERY_HIGH para VERY_LOW por exemplo ele devolve a collection 
porém muda o nome par chave valor, ficando chave : nome da classe por inteiro : valor;

Otávio Garcia

unread,
Apr 26, 2012, 12:08:12 PM4/26/12
to caelum-...@googlegroups.com
Poxa, vivendo e aprendendo.... eu poderia jurar que era uma interface.

De qualquer forma, o vraptor lê os componentes internos através da classe BaseComponents, ou seja, nem tudo que é interno do vraptor precisa do @Component.

Abraço

Jose Maria de Oliveira

unread,
Apr 26, 2012, 12:11:45 PM4/26/12
to caelum-...@googlegroups.com

Legal..... eu tambem estou aprendendo, e muiito...

 

Vlw.

 

Abs

 

José Maria de Oliveira

Eccox Technology

Tel.: + 55 11 4133-1969

Fax: + 55 11 4133-1960

jose.o...@eccox.com.br

www.eccox.com.br

Al. Rio Negro, 433, 4º andar, Edifício I

Alphaville, São Paulo, Brasil - CEP: 06454-904

 

"Seus negócios, disponíveis a qualquer momento, em qualquer lugar"

 

Antes de imprimir, pense no compromisso com o Meio Ambiente.

 

 

Lucas Cavalcanti

unread,
Apr 26, 2012, 12:43:21 PM4/26/12
to caelum-...@googlegroups.com
tenta não colocar a prioridade...

vc passou o mapper que veio do xstream do parâmetro certo?

[]'s

2012/4/26 Dev.Softhouse <sup...@softhouse.inf.br>
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/aYf3yFVB1KQJ.
To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Suporte

unread,
Apr 27, 2012, 8:29:00 AM4/27/12
to caelum-...@googlegroups.com

Bom dia a todos.

 

Então Lucas, se eu não coloco prioridade ai acontece o que falei antes, mesmo usando o recursive() a collection não serializa.

Quanto ao que vc falou sobre o mapper, eu só tentei fazer, assim:

 

xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()));

 


De: caelum-...@googlegroups.com [mailto:caelum-...@googlegroups.com] Em nome de Lucas Cavalcanti
Enviada em: quinta-feira, 26 de abril de 2012 13:43
Para: caelum-...@googlegroups.com
Assunto: Re: Consumir JSON.

 

tenta não colocar a prioridade...

xstream.getMapper();

isso

2012/4/26 Suporte <sup...@softhouse.inf.br>

De: caelum-...@googlegroups.com [mailto:caelum-...@googlegroups.com] Em nome de Lucas Cavalcanti
Enviada em: quinta-feira, 26 de abril de 2012 10:24
Para: caelum-...@googlegroups.com
Assunto: Re: Consumir JSON.

O XStream por padrão seta os atributos diretamente... mas dá pra configurar ele pra sempre usar os setters. Quer fazer isso?

precisa sobrescrever o componente XStreamBuilder (estendendo XStreamBuilderImpl e anotando @Component), e sobrescrever
o método que configura o xstream adicionando o converter JavaBeanConverter (ou algo parecido com isso).

2012/4/26 Suporte <sup...@softhouse.inf.br>

Bom dia. Obrigado era isso mesmo, eu tinha feito da outra vez, porém como os dados estavam mal formados não percebi este outro problema....

Nesse processo de consumir o JSON o XStream não usa os setters das classes de modelo? Pergunto por que estou mandando um atributo “id”:” ” com campo em branco (String) daí no setter da classe bairro fiz uma verificação que sele for

Em branco seta para null, mas ele passa direto, imprimi no console os dados do objeto o id está ficando com o valor “ ”, com o IOGI eu usava ele antes para evitar esse problema de setar valores “ ”, no lugar ele sempre setava null.

 

De: caelum-...@googlegroups.com [mailto:caelum-...@googlegroups.com] Em nome de Lucas Cavalcanti
Enviada em: quinta-feira, 26 de abril de 2012 09:55


Para: caelum-...@googlegroups.com
Assunto: Re: Consumir JSON.

 

2012/4/26 Suporte <sup...@softhouse.inf.br>

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/0cU8c531SbMJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/T8_D8OyXAxMJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/LvtN0lSNv70J.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/tbU9lIgiEhwJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/G7qw6XK-insJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/KM0KrcCAUXUJ.

To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/aYf3yFVB1KQJ.
To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

 

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

Lucas Cavalcanti

unread,
Apr 27, 2012, 10:26:34 AM4/27/12
to caelum-...@googlegroups.com
vc tem o getter e o setter da collection?

2012/4/27 Suporte <sup...@softhouse.inf.br>

Suporte

unread,
Apr 27, 2012, 10:43:13 AM4/27/12
to caelum-...@googlegroups.com

Lá na classe grid que eu to serializando eu tenho:

 

public void setList(Collection<T> list)  {

this.list = list;

            }            

 

public Collection<T> getList() {

                        return list;

Lucas Cavalcanti

unread,
Apr 27, 2012, 10:42:51 AM4/27/12
to caelum-...@googlegroups.com
pode ser que ele não curta mto collection... tem como vc testar com List?

2012/4/27 Suporte <sup...@softhouse.inf.br>

Jose Maria de Oliveira

unread,
Apr 27, 2012, 10:54:06 AM4/27/12
to caelum-...@googlegroups.com

Lucas, uma vez tive problema também e você tinha pedido para criar esta classe:

 

 

@Component

public class GovExtJson extends DefaultExtJson implements GovExtJSJson {

                protected static final Logger logger = LoggerFactory.getLogger(GovExtJson.class);

               

                public GovExtJson(final HttpServletResponse response, final TypeNameExtractor extractor, final ProxyInitializer initializer) throws IOException {

                               super(response, extractor, initializer);

                              

                               logger.debug(this.getClass().getName() + " -> GovExtJson() -> entering");

                              

                               XStream xstream = (XStream) new Mirror().on(this).get().field("xstream");

 

                    xstream.registerConverter(new CollectionConverter(xstream.getMapper()) {

            /* (non-Javadoc)

             * @see com.thoughtworks.xstream.converters.collections.CollectionConverter#canConvert(java.lang.Class)

             */

            @Override

            @SuppressWarnings("rawtypes")

            public boolean canConvert(Class type) {

                return Collection.class.isAssignableFrom(type);

            }

        });

                   

                    logger.debug(this.getClass().getName() + " -> GovExtJson() -> exiting");

                }

}

 

 

Porém não uso Collection e sim List.

 

Abs

 

 

 

 

José Maria de Oliveira

Eccox Technology

Tel.: + 55 11 4133-1969

Fax: + 55 11 4133-1960

jose.o...@eccox.com.br

www.eccox.com.br

Al. Rio Negro, 433, 4º andar, Edifício I

Alphaville, São Paulo, Brasil - CEP: 06454-904

 

"Seus negócios, disponíveis a qualquer momento, em qualquer lugar"

 

Antes de imprimir, pense no compromisso com o Meio Ambiente.

 

 

Lucas Cavalcanti

unread,
Apr 27, 2012, 11:05:55 AM4/27/12
to caelum-...@googlegroups.com
Tenta incluir o converter da collection que o Jose passou então

2012/4/27 Jose Maria de Oliveira <jose.O...@eccox.com.br>

Suporte

unread,
Apr 27, 2012, 11:59:27 AM4/27/12
to caelum-...@googlegroups.com

Eu tentei usar essa classe mas no to achando esse interface GovExtJson.

 


Suporte

unread,
Apr 27, 2012, 12:08:48 PM4/27/12
to caelum-...@googlegroups.com

Tentei usar essa classe, porém sem o implements.

Nessa linha:  XStream xstream = (XStream) new Mirror().on(this).get().field("xstream");

Tive que deixar o Mirror como static:

XStream xstream = (XStream) Mirror.on(this).get().field("xstream");

 

Não sei se o que eu mudei afetou alguma coisa, mas o resultado foi o mesmo (estou usando list), a lista não veio.


Suporte

unread,
Apr 27, 2012, 12:15:12 PM4/27/12
to caelum-...@googlegroups.com

Ops, descumpem, com essa classe no component a lista veio, porém o id veio como “”  não usou meu setter para mudar para null;

Jose Maria de Oliveira

unread,
Apr 27, 2012, 12:15:55 PM4/27/12
to caelum-...@googlegroups.com

Desculpa!

 

Esta interface é minha.

 

Pode tirar do código.

Lucas Cavalcanti

unread,
Apr 27, 2012, 12:52:30 PM4/27/12
to caelum-...@googlegroups.com
Não era pra copiar a classe inteira do José,

era pra vc copiar as linhas do CollectionConverter, e incluí-las no seu XStreamBuilder

2012/4/27 Jose Maria de Oliveira <jose.O...@eccox.com.br>

Desculpa!

Dev.Softhouse

unread,
Apr 27, 2012, 3:46:03 PM4/27/12
to caelum-...@googlegroups.com
Tb não deu certo. o result não serializa a lista.


Em sexta-feira, 27 de abril de 2012 13h52min30s UTC-3, Lucas Cavalcanti escreveu:
Não era pra copiar a classe inteira do José,

era pra vc copiar as linhas do CollectionConverter, e incluí-las no seu XStreamBuilder

2012/4/27 Jose Maria de Oliveira <jose.O...@eccox.com.br>

Desculpa!

 

Esta interface é minha.

 

Pode tirar do código.

 

Abs

 

José Maria de Oliveira

Eccox Technology

Tel.: + 55 11 4133-1969

Fax: + 55 11 4133-1960

jose.o...@eccox.com.br

www.eccox.com.br

Al. Rio Negro, 433, 4º andar, Edifício I

Alphaville, São Paulo, Brasil - CEP: 06454-904

 

"Seus negócios, disponíveis a qualquer momento, em qualquer lugar"

 

Antes de imprimir, pense no compromisso com o Meio Ambiente.

 

 

De: caelum-vraptor@googlegroups.com [mailto:caelum-vraptor@googlegroups.com] Em nome de Suporte
Enviada em: sexta-feira, 27 de abril de 2012 12:59
Para: caelum-vraptor@googlegroups.com
Assunto: RES: Consumir JSON.

 

Eu tentei usar essa classe mas no to achando esse interface GovExtJson.

 

2012/4/27 Suporte <sup...@softhouse.inf.br>

De: caelum-vraptor@googlegroups.com [mailto:caelum-vraptor@googlegroups.com] Em nome de Lucas Cavalcanti
Enviada em: sexta-feira, 27 de abril de 2012 11:27
Para: caelum-vraptor@googlegroups.com
Assunto: Re: Consumir JSON.

vc tem o getter e o setter da collection?

2012/4/27 Suporte <sup...@softhouse.inf.br>

Bom dia a todos.

 

Então Lucas, se eu não coloco prioridade ai acontece o que falei antes, mesmo usando o recursive() a collection não serializa.

Quanto ao que vc falou sobre o mapper, eu só tentei fazer, assim:

 

xstream.registerConverter(new JavaBeanConverter(xstream.getMapper()));

 

xstream.getMapper();

isso

2012/4/26 Suporte <sup...@softhouse.inf.br>

2012/4/26 Suporte <sup...@softhouse.inf.br>


Para: caelum-vraptor@googlegroups.com
Assunto: Re: Consumir JSON.

 

2012/4/26 Suporte <sup...@softhouse.inf.br>

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/0cU8c531SbMJ.


To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/T8_D8OyXAxMJ.


To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/LvtN0lSNv70J.


To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/tbU9lIgiEhwJ.


To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/G7qw6XK-insJ.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/KM0KrcCAUXUJ.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/aYf3yFVB1KQJ.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--

You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.

To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/caelum-vraptor?hl=en.

--
You received this message because you are subscribed to the Google Groups "caelum-vraptor" group.
To post to this group, send email to caelum-vraptor@googlegroups.com.
To unsubscribe from this group, send email to caelum-vraptor+unsubscribe@googlegroups.com.

Lucas Cavalcanti

unread,
Apr 27, 2012, 3:54:21 PM4/27/12
to caelum-...@googlegroups.com
talvez esteja ligado com isso: http://stackoverflow.com/questions/2456470/xstream-javabeanconverter-not-serializing-properties

solução é dar a prioridade -10 pro javaBeanConverter.

2012/4/27 Dev.Softhouse <sup...@softhouse.inf.br>
To view this discussion on the web visit https://groups.google.com/d/msg/caelum-vraptor/-/UgrW8e3sZcoJ.
To post to this group, send email to caelum-...@googlegroups.com.
To unsubscribe from this group, send email to caelum-vrapto...@googlegroups.com.

Dev.Softhouse

unread,
Apr 27, 2012, 4:15:07 PM4/27/12
to caelum-...@googlegroups.com
Obrigado Lucas, nem esquente mais com isso, depois eu vou dar uma estudada melhor nesse assunto, a unica coisa que o cara do post esqueceu de comentar, é que se baixar a prioridade funciona, porém o resultado da serialização muda, faz aquilo que falei.
"nome da classe + todos os pacotes " : " valor"

Suporte

unread,
Apr 27, 2012, 11:49:15 AM4/27/12
to caelum-...@googlegroups.com

Não vai também.

Reply all
Reply to author
Forward
0 new messages