[Java Rest] Erro ao retornar JSON
Olá, boa noite! Estou começando a aprender sobre rest e estou com um problema com o meu primeiro codigo, é o seguinte. Se eu retorno uma String, ele retorna normalmente, mas quando eu retorno como JSON, ele dá erro. Segue os codigos:
\\\\ Classe do obj test
public class test {
private String nome;
private String idade;
public test() {
this.nome = "";
this.idade = "";
}
public String getNome() { return nome; }
public void setNome(String nome) { this.nome = nome; }
public String getIdade() { return idade; }
public void setIdade(String idade) { this.idade = idade; }
}
\\\\Applet
@Path("/teste")
public class teste {
@GET
@Path("/list")
//@Produces(MediaType.APPLICATION_JSON + CHARSET)
@Produces(MediaType.APPLICATION_JSON)
public test listar() {
test Jean = new test();
Jean.setIdade("26");
Jean.setNome("Jean");
System.out.println(Jean.getNome()+Jean.getIdade());
return Jean;
}
}
\\\\Erro no navegador
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause
org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.
Obrigado!
\\\\ Classe do obj test
public class test {
private String nome;
private String idade;
public test() {
this.nome = "";
this.idade = "";
}
public String getNome() { return nome; }
public void setNome(String nome) { this.nome = nome; }
public String getIdade() { return idade; }
public void setIdade(String idade) { this.idade = idade; }
}
\\\\Applet
@Path("/teste")
public class teste {
@GET
@Path("/list")
//@Produces(MediaType.APPLICATION_JSON + CHARSET)
@Produces(MediaType.APPLICATION_JSON)
public test listar() {
test Jean = new test();
Jean.setIdade("26");
Jean.setNome("Jean");
System.out.println(Jean.getNome()+Jean.getIdade());
return Jean;
}
}
\\\\Erro no navegador
HTTP Status 500 - Internal Server Error
type Exception report
messageInternal Server Error
descriptionThe server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause
org.glassfish.jersey.server.ContainerException: java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
root cause
java.lang.NoClassDefFoundError: Could not initialize class org.eclipse.persistence.jaxb.BeanValidationHelper
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs.
Obrigado!
Jean Oliveira
Curtidas 0
Melhor post
José Soares
25/08/2018
Mano, não sei se seria o caso, mas tenta botar um @JSONIgnore em cima da classe que acredito que irá resolver.
GOSTEI 1
Mais Respostas
Jean Oliveira
25/08/2018
Diz que não encontrou dependências para esse include. Não funcionou =(
GOSTEI 0
Jean Oliveira
25/08/2018
Depois de pesquisar bastante, vi que era um problema com um dos modulos do glassfish. Troquei um dos arquivos que estavam na pasta dele e funcionou perfeitamente. Abraço!
Link da solução: https://www.ivonet.nl/2016/09/06/Could%20not%20initialize%20class%20org.eclipse.persistence.jaxb.BeanValidationHelper/
Link da solução: https://www.ivonet.nl/2016/09/06/Could%20not%20initialize%20class%20org.eclipse.persistence.jaxb.BeanValidationHelper/
GOSTEI 1
José Soares
25/08/2018
Olá Jean, que bom que conseguiu, abraços!
GOSTEI 0