Solucionado (ver solução)
Solucionado
(ver solução)
16
respostas

Handler processing failed; nested exception is java.lang.StackOverflowError

Depois de toda config tenho o erro! O que pode ser?

Hibernate: select tiporeceit0_.receitas_cat_id as receitas1_26_0_, tiporeceit0_.categoria_id as categori2_17_0_, cattiporec1_.id as id1_14_1_, cattiporec1_.cor_tipo_receita as cor_tipo2_14_1_, cattiporec1_.nome_tipo_receita as nome_tip3_14_1_ from categorias_has_receitas tiporeceit0_ inner join cat_tipo_receita cattiporec1_ on tiporeceit0_.categoria_id=cattiporec1_.id where tiporeceit0_.receitas_cat_id=?
Hibernate: select minhasrece0_.categoria_id as categori2_14_0_, minhasrece0_.receitas_cat_id as receitas1_17_0_, minhasrece1_.id as id1_26_1_, minhasrece1_.adicionar_observacao as adiciona2_26_1_, minhasrece1_.data_receita as data_rec3_26_1_, minhasrece1_.descricao_receita as descrica4_26_1_, minhasrece1_.pagamento as pagament5_26_1_, minhasrece1_.receita_fixa as receita_6_26_1_, minhasrece1_.receita_fixa_quantidade as receita_7_26_1_, minhasrece1_.receita_fixa_tempo as receita_8_26_1_, minhasrece1_.repetir_lanc as repetir_9_26_1_, minhasrece1_.repetir_por_periodo as repetir10_26_1_, minhasrece1_.valor_receita as valor_r11_26_1_ from categorias_has_receitas minhasrece0_ inner join minhas_receitas minhasrece1_ on minhasrece0_.receitas_cat_id=minhasrece1_.id where minhasrece0_.categoria_id=?
Hibernate: select tiporeceit0_.receitas_cat_id as receitas1_26_0_, tiporeceit0_.categoria_id as categori2_17_0_, cattiporec1_.id as id1_14_1_, cattiporec1_.cor_tipo_receita as cor_tipo2_14_1_, cattiporec1_.nome_tipo_receita as nome_tip3_14_1_ from categorias_has_receitas tiporeceit0_ inner join cat_tipo_receita cattiporec1_ on tiporeceit0_.categoria_id=cattiporec1_.id where tiporeceit0_.receitas_cat_id=?
19:30:07.275 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor - Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
19:30:07.276 [http-nio-8080-exec-7] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils - Closing JPA EntityManager
19:30:07.281 [http-nio-8080-exec-7] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.StackOverflowError
    at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1305)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:979)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at com.github.dandelion.datatables.core.web.filter.DatatablesFilter.doFilter(DatatablesFilter.java:75)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at com.github.dandelion.core.web.DandelionFilter.doFilter(DandelionFilter.java:138)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.StackOverflowError: null
    at com.google.gson.stream.JsonWriter.beforeName(JsonWriter.java:586)
    at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:401)
    at com.google.gson.stream.JsonWriter.value(JsonWriter.java:495)
    at com.google.gson.internal.bind.TypeAdapters$7.write(TypeAdapters.java:246)
    at com.google.gson.internal.bind.TypeAdapters$7.write(TypeAdapters.java:231)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.write(ReflectiveTypeAdapterFactory.java:99)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.write(ReflectiveTypeAdapterFactory.java:219)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.write(TypeAdapterRuntimeTypeWrapper.java:68)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:96)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:60)
    at com.google.gson.Gson$FutureTypeAdapter.write(Gson.java:899)
16 respostas

Pode mostrar o código Clerman? Está aparentando um código em loop. Tipo você está consultando uma entidade que chama uma outra que chama a primeira entidade e por assim vai...

Aqui esta!

A classe MinhasReceitas se relaciona com DataTableMinhasReceitas que por sua vez apresenta os dados, e MinhasReceitas também se relaciona com as outras classes listadas abaixo

@RequestMapping(value = "listJson", method = RequestMethod.GET, produces = "application/json")
    public @ResponseBody void doGet(HttpServletRequest request, HttpServletResponse response) throws Throwable{

        // Minhas receitas que se realciona com outras classes nela atributos desse realcionamento
        List<MinhasReceitas> listMinhasReceitas = receitasService.findAll();

        // Essa classe recebe os parametros da datatable
        DataTableMinhasReceitas dataTableMinhasReceitas = new DataTableMinhasReceitas();

        // Seta a lista do relacionamento
        dataTableMinhasReceitas.setAaData(listMinhasReceitas);

        Gson gson = new GsonBuilder().setPrettyPrinting().create();
        String json = gson.toJson(dataTableMinhasReceitas);

        response.getWriter().print(json);

    }

Classes que se relacionam

public class MinhasReceitas extends AbstractPersistable<Long> {

    @Column(name = "descricao_receita", nullable = false)
    private String descricaoReceita;

    @Column(name = "data_receita", nullable = true)
    @DateTimeFormat(pattern = "dd/MM/yyyy", iso = ISO.DATE)
    private LocalDate dataReceita;

    @Column(name = "valor_receita", nullable = true)
    @NumberFormat(style = Style.CURRENCY, pattern = "###,##0.00")
    private BigDecimal valorReceita;

    @Column(name = "receita_fixa", nullable = false)
    private boolean receitaFixa;

    @Column(name = "receita_fixa_quantidade", nullable = true)
    private Integer receitaFixaQuantidade;

    @Enumerated(EnumType.STRING)
    @Column(name = "receita_fixa_tempo", nullable = true)
    private ReceitaFixaTempo receitaFixaTempo;

    @Column(name = "repetir_lanc", nullable = true)
    private boolean repetirLancReceita;

    @Enumerated(EnumType.STRING)
    @Column(name = "repetir_por_periodo", nullable = true)
    private RepetirPorPeriodo repetirPorPeriodo;

    @Column(name = "pagamento", nullable = false)
    private boolean pagamento;

    @Column(name = "adicionar_observacao", nullable = false)
    private String addObservacao;

    @ManyToMany
    @JoinTable(name = "categorias_has_receitas", joinColumns = @JoinColumn(name = "receitas_cat_id"), inverseJoinColumns = @JoinColumn(name = "categoria_id"))
    private List<CatTipoReceitas> tipoReceitas;

    @ManyToMany
    @JoinTable(name = "contas_has_receitas", joinColumns = @JoinColumn(name = "receitas_id"), inverseJoinColumns = @JoinColumn(name = "contas_id"))
    private List<MinhasContas> minhasContas;

    @ManyToMany
    @JoinTable(name = "etiquetas_has_receitas", joinColumns = @JoinColumn(name = "receitas_id"), inverseJoinColumns = @JoinColumn(name = "etiquetas_id"))    
    private List<Etiquetas> etiquetas;
//ggas
}
public class CatTipoReceitas extends AbstractPersistable<Long>{

    @Column(name = "nome_tipo_receita", nullable = false, length = 30)
    private String nome;

    @Column(name = "cor_tipo_receita", nullable = false, length = 7)
    private String corTipoReceita;

    @ManyToMany
    @JoinTable(
            name = "categorias_has_receitas", 
            joinColumns = @JoinColumn(name = "categoria_id"), 
            inverseJoinColumns = @JoinColumn(name = "receitas_cat_id"))
    private List<MinhasReceitas> minhasReceitas;
//ggas
}
public class MinhasContas extends AbstractPersistable<Long> {

    // @NotBlank
    // @Length(min = 3, max = 30)
    @Column(nullable = false, unique = true, length = 30)
    private String nome;

    @Column(nullable = true)
    @DateTimeFormat(pattern = "dd/MM/yyyy HH:mm:ss", iso = ISO.DATE_TIME)
    private LocalDate dataAcesso;

    @Column(nullable = false)
    @NumberFormat(style = Style.CURRENCY, pattern = ("###,##0.00"))
    private BigDecimal saldoAnterior;

    @Column(nullable = false)
    @NumberFormat(style = Style.CURRENCY, pattern = ("###,##0.00"))
    private BigDecimal saldoAtual;

    @Column(nullable = true)
    @NumberFormat(style = Style.CURRENCY, pattern = ("###,##0.00"))
    private BigDecimal saldoFinal;

    @Enumerated(EnumType.STRING)
    @Column(nullable = true)
    private CatTipoConta tipo;

    @Column(nullable = true)
    private String cor;

    @Column(nullable = true)
    private Boolean dashBoard;

    @ManyToMany(cascade = CascadeType.REMOVE)
    @JoinTable(name = "contas_has_receitas", joinColumns = @JoinColumn(name = "contas_id"), inverseJoinColumns = @JoinColumn(name = "receitas_id"))
    private List<MinhasReceitas> minhasReceitas;

    @ManyToMany
    @JoinTable(name = "contas_has_transfer", joinColumns = @JoinColumn(name = "contas_id"), inverseJoinColumns = @JoinColumn(name = "transfer_id"))
    private List<Transferencias> transferencias;
//ggas
}
public class DataTableMinhasReceitas extends AbstractPersistable<Long> {

    int iTotalRecords;
    int iTotalDisplayRecords;
    String sEcho;
    String sColumns;

    @OneToMany
    List<MinhasReceitas> aaData;

//ggas
}

Provavelmente é uma referência circular que você tem entre elas! Consegue verificar?

É esperado o GSON / Json writer fazer isso se voce tem referencias assim.

Olá Paulo Silveira, muito grato pela atenção! Não consigo verificar! Vou tentar debugar e ver o que acontece! Pode dar uma dica por onde começo a verificar?

Oi Clerman,

eu estou chutando, mas tente colocar na classe MinhasReceitas na frente do atributo tipoReceitas a palavra chave transient:

    private transient List<CatTipoReceitas> tipoReceitas;

Isso faz que Gson ignora esse atributo na serialização.

abs

Clerman, a sua referencia circular é essa que voce fez o many to many: minhas receitas tem minhas contas, e vice versa.

Ai ele começa a serializar o a Conta de ID1 e passa a serializar, por exempo, a receita de ID 7, ai depois a receita de ID 7 passa a serializar a Conta de ID1 e isso infinitamente. talvez haja ainda outras referencias circulares que nao detectei, pois nao tenho acesso aos seus dados tambem

Tem algumas formas de resolver isso: 1- mais bonita. criar Value Objects apenas com o que voce quer serializar 2- usar a api do gson ou outro serializados de json. nao manjo de gson, mas tem essa anotacao: https://static.javadoc.io/com.google.code.gson/gson/2.6.2/com/google/gson/annotations/Expose.html

que voce precisa colcoar em tudo que quer serializar, mas ai precisa ativar essa configuracao na hora de dar new em Gson builder: GsonBuilder.excludeFieldsWithoutExposeAnnotation()

Nico, se ele colocar transiente ai, acho que o problema sera que o hibernate tambem vai ignorar. mas é um bom teste.

Olá Paulo, Nico! Obrigado pelas respostas. Indo por parte, fiz a sugestão mais do Nico e retorna outro erro:

15:31:17.375 [http-nio-8080-exec-2] WARN org.springframework.web.context.support.AnnotationConfigWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'minhasReceitasService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.augebit.contas.repository.MinhasReceitasRepository br.com.augebit.contas.service.MinhasReceitasService.receitasRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'minhasReceitasRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract java.util.List br.com.augebit.contas.repository.MinhasReceitasRepository.findByEtiquetasNome(java.lang.String)!
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@31ecc721: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,springMvcConfig,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,springDataConfig,autorService,avatarService,businessService,catTipoDespesasService,catTipoReceitasService,etiquetasServices,grupoDespesasService,minhasContasService,minhasDespesasService,minhasReceitasService,transferenciasService,usuarioService,autorController,avatarController,catTipoDespesasController,catTipoReceitasController,dataTableServlet,definicaoDespesasController,errorPagesController,etiquetasController,grupoDespesasController,homeController,minhasContasContoller,minhasDespesasController,minhasReceitasController,testListJsonController,transferenciasController,usuarioController,receitasValidator,org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration,org.springframework.transaction.config.internalTransactionAdvisor,transactionAttributeSource,transactionInterceptor,org.springframework.transaction.config.internalTransactionalEventListenerFactory,transactionManager,JpaVendorAdapter,entityManagerFactory,dataSource,org.springframework.data.jpa.repository.config.JpaRepositoryConfigExtension#0,org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport_Predictor,emBeanDefinitionRegistrarPostProcessor,jpaMappingContext,jpaContext,personRepository,businessRepository,catTipoReceitasRepository,autorRepository,minhasReceitasRepository,tranferenciasRepository,avatarRepository,minhasContasRepository,catTipoDespesasRepository,grupoDespesasRepository,etiquetasRepository,usuarioRepository,minhasDespesasRepository,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration,mvcValidator,mvcPathMatcher,mvcUrlPathHelper,mvcViewResolver,handlerExceptionResolver,requestMappingHandlerAdapter,mvcResourceUrlProvider,mvcContentNegotiationManager,defaultServletHandlerMapping,mvcConversionService,viewControllerHandlerMapping,mvcUriComponentsContributor,httpRequestHandlerAdapter,simpleControllerHandlerAdapter,resourceHandlerMapping,requestMappingHandlerMapping,beanNameHandlerMapping,jspViewResolver,multipartResolver,getOpenEntityManagerInViewInterceptor,org.springframework.orm.jpa.SharedEntityManagerCreator#0]; root of factory hierarchy
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#733d4a54': [minhasDespesasRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#18fdb430': [(inner bean)#733d4a54]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#66b4bd54': [minhasContasRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#7ec8f444': [(inner bean)#66b4bd54]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#1f075868': [grupoDespesasRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#21acf126': [(inner bean)#1f075868]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#25e0eed8': [etiquetasRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#3192c0a6': [(inner bean)#25e0eed8]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#6fc317bf': [catTipoReceitasRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#64af4627': [(inner bean)#6fc317bf]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#4cf2ad44': [catTipoDespesasRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#59d16c04': [(inner bean)#4cf2ad44]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#69d8f04c': [businessRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#32199350': [(inner bean)#69d8f04c]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#76c5b7e2': [avatarRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#46f87c6b': [(inner bean)#76c5b7e2]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#702adba': [autorRepository]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean '(inner bean)#5627ac49': [(inner bean)#702adba]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy() on bean with name 'jpaMappingContext'
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'entityManagerFactory'
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy method 'close' on bean with name 'dataSource'
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Retrieved dependent beans for bean 'springMvcConfig': [org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration]
15:31:17.375 [http-nio-8080-exec-2] DEBUG org.springframework.beans.factory.support.DisposableBeanAdapter - Invoking destroy() on bean with name 'mvcValidator'
15:31:17.375 [http-nio-8080-exec-2] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'minhasReceitasService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.augebit.contas.repository.MinhasReceitasRepository br.com.augebit.contas.service.MinhasReceitasService.receitasRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'minhasReceitasRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract java.util.List br.com.augebit.contas.repository.MinhasReceitasRepository.findByEtiquetasNome(java.lang.String)!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:666)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:538)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:492)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:158)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1227)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:833)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1524)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1480)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private br.com.augebit.contas.repository.MinhasReceitasRepository br.com.augebit.contas.service.MinhasReceitasService.receitasRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'minhasReceitasRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract java.util.List br.com.augebit.contas.repository.MinhasReceitasRepository.findByEtiquetasNome(java.lang.String)!
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
    ... 33 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'minhasReceitasRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract java.util.List br.com.augebit.contas.repository.MinhasReceitasRepository.findByEtiquetasNome(java.lang.String)!
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
    ... 35 common frames omitted
Caused by: java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract java.util.List br.com.augebit.contas.repository.MinhasReceitasRepository.findByEtiquetasNome(java.lang.String)!
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:106)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:214)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:435)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:220)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:266)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:252)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
    ... 45 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [etiquetas] on this ManagedType [org.springframework.data.jpa.domain.AbstractPersistable]
    at org.hibernate.jpa.internal.metamodel.AbstractManagedType.checkNotNull(AbstractManagedType.java:144)
    at org.hibernate.jpa.internal.metamodel.AbstractManagedType.getAttribute(AbstractManagedType.java:130)
    at org.hibernate.jpa.internal.metamodel.AbstractManagedType.getAttribute(AbstractManagedType.java:128)
    at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:497)
    at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.getTypedPath(JpaQueryCreator.java:325)
    at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:268)
    at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:169)
    at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:98)
    at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:49)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
    at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.<init>(PartTreeJpaQuery.java:118)
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer.<init>(PartTreeJpaQuery.java:241)
    at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:68)
    at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103)
    ... 54 common frames omitted

é o que eu falei: o transient vai atrapalhar o hibernate

faca a minha sugestao de marcar o que voce quer que seja exportado com @Expose, ligue a configuracao, e nao marque o @Expose no campo do many to many do minhasreceitas

Paulo para seguir sua sugestão, preciso saber como crio os ValueObjects? E como ativo a config que passou? É no SpringDataConfig.java? Obrigado!

a configuracao é essa aqui:

Gson gson = new GsonBuilder()
     .excludeFieldsWithoutExposeAnnotation()...... (continua como antes)

ai marca todo mundo que voce quer expor com @Expose

do value objects precisaria entender seu modelo e escrever todas as classes, baseado em onde voce vai usar, nao teria dados suficientes pra te dizer. tente a da api e veja se é suficiente pra voce

solução!

Perfeito Paulo Silveira, perfeito, mais um super aprendizado usando o @Expose, muito bom mesmo! Agradeço muito a atenção!

Olá Paulo, mais um dúvida. Como anoto com o @Expose o id uma vez que o Spring que o gerencia com o extends AbstractPersistable , e não tenho acesso a ele(id)?

Clerman, é uma boa pergunta!

Eu realmente nao conheco a api do gson e em uma procurada rapida nao achei. Voce pode usar outro framework de serailizacao de json? Ai fica bem mais facil para customizarmos isso

Poxa, se me passar mudo com certeza! Qual framework serailizacao de json facilitaria a inserção desse id? E, na classe de entidade não tem como fazer o @expose eplo Spring?

Clerman, vou te dar duas posisbilidades, mas voce abre esse questionamento numa nova thread? assim outras pessoas podem ver (quando a thread fica marcada como resolvida, poucas pessoas vem ver :), pois o problema inicial foi achado). ai posta o link aqui?