Grails cannot cast JSON array to HashMap -


I have the following JSON (stored in strings in Groovy):

  { "Isfizz": "true", "buzzProperties": [{"foo": "bar"}, {"widget": 35}], "name": "dummy1"}  

  Content register () {def JSONObject = request.JSON content stuff: In my Grails controller I have the following method that handles this JSON as HTTP request and to read JSON in Groove Attacks Vars = new content () stuff.isFizz = jsonObject.isFizz stuff.buzzProperties = jsonObject.buzzProperties // stuff.buzzProperties a HashMap stuff.name = JsonObject.name stuff}  

When the controller executes the method (when this request is received) I get the following exception:

  Can not remove ['foo': 'bar'}, {"widget": 35}] 'orbit' with org.codehaus .groovy.grails.web.json.JSONArray java.util.Map ' 'For class': groovy.lang.GroovyRuntimeException: manufacturer match for java.util.Map (org.codehaus.groovy.grails) could not be found. Web.json.JSONObject, org.codehaus.groovy.grails.web.json.JSONObject). The stacktrace is as follows: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Object can not be given '[["foo": "bar"}, {"widget": 35}]' square with 'org.codehaus .groovy.grails. Due to web.json.JSONArray java.util.Map 'for class': groovy.lang.GroovyRuntimeException: for creator match could not be found: java.util.Map (org.codehaus.groovy.grails.web.json .JSONObject, Org.codehaus.groovy.grails.web.json.JSONObject)  

I investigated Jasonson and it is completely legitimate JSON what is happening? Keep this fact in mind that buzzProperties a map

This is a list ( {} versus [] ). That is why casting can not move forward Either change the buzzProperties type to list or send a valid map .

Edit

The Jason string you send should be defined in the following manner:

  {"IsFizz": "true", "buzzProperties": {"foo": "bar", "widget": 35}, "name": "dummy 1"}  

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -