I'm wondering how I would create a Grails domain class with JavaScript objects as variables on the inside of the class.
For example, I am sending a JSON object that looks like this:
{
"name":"task",
"type":{
"label":"Work",
"id":1
},
"priority":{
"label":"Mid Priority",
"id":2
},
"completed":false,
"comments":"",
"creator":"user",
"assignedTo":"user"
}
As you can see, "type" and "priority" are objects in their own. My grails domain class looks like this currently:
package server
class Item {
//String username
String name
String type
String priority
boolean completed = false
String comments
String creator
String assignedTo
static constraints = {
name nullable: false
priority nullable: true
type nullable: true
comments nullable: true
creator nullable: false
assignedTo nullable: false
}
}
Obviously the string is incorrect, but I don't know what it should be? Right now everything is saved as it should be in the JSON list except for the type and priority.
For the SQL DBs no other alternatives other than saving the JSON as a string exist. All solutions have marshalling/unmarshalling at some stage, but the data is still stored as a TEXT
or BLOB
in a table.
NoSQL DB-s like mongo do allow you to store the BSON object as it is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.