是否有一种简单的方法可以将 JSON 字符串反序列化为支持嵌入式关联的域类;belongsTo 和 hasMany
{
name: "Customer",
contact: {
name: "Contact"
}
}
class Customer {
name
Contact contact
}
class Contact {
String name
static belongsTo = [customer:Customer]
}
在我的控制器中,我想做以下事情
def save() {
def customer = new Customer(request.JSON)
customer.save();
}
现在我被迫做
def save() {
def contact = new Contact(request.JSON.contact);
def customer = new Customer(request.JSON);
customer.contact = contact;
customer.save();
}