How to store JSON data using GORM Database for MySQL?

I have a dynamic object that needs to be saved, whose definition and values ​​change based on different users. You can think of them as dynamic forms that are first defined by the administrator and then filled in by different users.

I don't have a MySQL alternative for my project, so no db-free schema is out of the question.

I could do it using regular relational model stores and there are values ​​on multiple tables, but that was too clunky. So I decided to store these dynamic objects as JSON in a MySQL table.

Is this a good approach? If you can't suggest any correct alternatives?

Anyway I'm having a problem retrieving an object from JSON from a database using Grails. This is my example class where definition is the field where the JSON needs to be stored.

String subJobType
String definition

static constraints = {
    definition nullable: false

static mapping = {
    definition sqlType: 'MEDIUMTEXT',type: 'text'


I can only get the definition field as a string, but I want to return an object instead.

I could get all the objects first and then convert the entire definition field of each object to JSON, but that doesn't seem like a good idea.


source to share

All Articles