Grails/Groovy adding properties to existing Java class, losing them when trying to serialize using JSON converter?
By : Alec De Ruiter
Date : March 29 2020, 07:55 AM
like below fixes the issue I think the JSON conversion in grails does not pick up dynamically added properties. Maybe you should register your own object marshaller for the class in question? code :
def init = {servletContext ->
JSON.registerObjectMarshaller(ResetRequest) {req->
[
targetIp:req.targetIp
//etc
]
}
|
JSON converter in Grails
By : Anton Vladimirov
Date : March 29 2020, 07:55 AM
like below fixes the issue You can register your own JSON marshaller (at BootStrap.groovy, for example), like: code :
JSON.registerObjectMarshaller(Person) { Person it ->
return [
id : it.id,
email : it.email
]
}
|
How to set date format for JSON converter in Grails
By : Md Jahid Cprs
Date : March 29 2020, 07:55 AM
|
Grails JSON converter and JSONObject code breaks when moved to src/groovy
By : user2297562
Date : March 29 2020, 07:55 AM
hop of those help? You've declared jsonify() and cleanJson() as instance methods and try to use them as static. Declare them as static and it should work: code :
class JsonUtils {
def static jsonify(obj, ArrayList removeableKeys = []) {
(...)
}
def static cleanJson(json) {
(...)
}
}
|
grails json converter only returns strings not numbers, integers or doubles
By : Victoria
Date : March 29 2020, 07:55 AM
this will help I had this same issue. The only way I could get it to work was like this... Add this to top of your Service Class: code :
import groovy.json.*
def testMap(){
//my results from a query
List query = [[name:"price",value:"4.23",type:"double"],[name:"title",value:"box",type:"string"]]
def slrp = new JsonSlurper()
def results = [:]
query.each{ row ->
if (row.type == "double"){
//results << ["'${row.name}'": "${row.value}"]
results << slrp.parseText('{"' + row.name + '":' + row.value + '}')
}
else
{
//what do I do here?
results << slrp.parseText('{"' + row.name + '":"' + row.value + '"}')
//results << ["'${row.name}'": "'${row.value}'"]
}
}
return results
}
{"price":4.23,"title":"box"}
|