I have searched many post here but I still couldn't find the answer yet.
Problem: I want to parse this JSON:
{
"price": {
"currency": {
"class": "com.yintagoka.ad.Currency",
"id": {
"class": "org.bson.types.ObjectId",
"inc": -612166639,
"machine": -1775927134,
"new": false,
"time": 1393682821000,
"timeSecond": 1393682821
},
"code": "USD",
"longName": "United States Dollar",
"name": "USD",
"symbol": null
},
"amount": 100
},
"title": "title",
"description": "desc"
}
to become an Object in my Grails server
class House {
ObjectId id
String name
String title
Price price
// ... many more
}
class Price {
BigDecimal amount
Currency currency
}
class Currency {
ObjectId id
String code
String longName
String name
String symbol
}
Grails did almost all the heavy stuff for me, but it can't generate the ObjectId. So I will have Object Currency with all the property name filled with the value but the id will be null.
How can I tell Grails to render the ObjectId as well, preferably automatically.
Note: I don't want to use String for my id.
I also read a post that I can set it manually by request.JSON, but the problem is that I always get an empty map.
def save(House house) {
print('request = '+request.JSON)
print('house = '+house)
print('params = '+params)
}
out:
request = [:]
house = com.yintagoka.ad.House@217b1ead[id=<null>,title=title,description=desc,price=com.yintagoka.ad.Price@1a1b0107[amount=100,currency=com.yintagoka.ad.Currency@62e07ff4[id=<null>,name=USD,longName=United States Dollar,code=USD,symbol=<null>]]
params = [action:delete, controller:house]