apache / apache/grails-core

How to convert entity to JSON string when using gorm-hibernate in SpringBoot

Open
#14,453 5 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-hibernate5
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

I use gorm-hibernate in SpringBoot (and Micronaut) with Groovy.
When I use JsonSlurper/JsonBuilder to convert entity class to JSON string, it happens to Stackoverflow error . You may refer to below link for getting detail exception dump:
[https://stackoverflow.com/questions/56122167/when-using-hibernate-gorm-how-to-convert-domain-class-into-json-string](https://stackoverflow.com/questions/56122167/when-using-hibernate-gorm-how-to-convert-domain-class-into-json-string)

It seems that both _JsonSlurper_ and _JsonBuilder_ can not handle entity classes built from GORM.

So, is there any elegant way to convert domain classes to JSON string in Micronaut ? Please don't ask me to use Jackson library because the approach way of Jackson is so urgly.

I know in Grails, _grails.converters.JSON_ can convert a domain class to JSON string without any problem. So, is it possible to add the similar feature of _grails.converters.JSON_ into gorm-hibernate ?

Contributor guide

Open the contributing guide

Research direction

Start with the linked StackOverflow exception and the behavior of JsonSlurper and JsonBuilder when given GORM entity classes. Compare that with grails.converters.JSON and determine the intended scope for an equivalent feature in gorm-hibernate or Micronaut; done requires an agreed serialization approach and evidence that entity conversion avoids the reported StackOverflow error.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, spring-boot
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.