I have such controller in my grails project:
def submit() {
def json = request.JSON
Share share = new Share(json)
share.save(flush: true, failOnError: true)
}
Class Share looks like this:
class Share {
String timestamp
String deviceName
String originMessage
Share(JSONObject originalMessage) {
println "Run JSON constructor"
println "$originalMessage"
originMessage = originalMessage.toString()
timestamp = originalMessage.timestamp
deviceName = originalMessage.device
}
It recives JSON request and try to persist in data base.
I get such error in my console on failOnError:
- Field error in object 'com.entity.Share' on field 'deviceName': rejected value [null];
- Field error in object 'com.entity.Share' on field 'originMessage': rejected value [null]; codes
A lot of dancing around find one possible way: in controller convert JSON to string and pass it in constructor where parameter would be type String and then parse it back in JSON using JSON converter. But why I can not pass JSON Object as parameter correctly. What happens?