grails-plugins / grails-rest-client-builder

REST client plugin that uses Spring's RestTemplate
http://grails.org/plugin/rest-client-builder
Apache License 2.0
65 stars 32 forks source link

post json body containing object #32

Open wureka opened 9 years ago

wureka commented 9 years ago

I have a problem when using RestBuilder to post data containing json string: I hope the server side could get the json result as below: {"to":["u080859b6886c2269b28999fb9677535b"],"toChannel":"1383378250","eventType":"138311608800106203","content":{"contentType":1,"toType":1,"text":"HELLO"}}

My code is as below: def resp = rest.post("http://localhost:8080/I-MSG_HUB/line/mockReceiving/?uid=WUREKA"){ header 'X-Line-ChannelToken', LINE_ACCESS_TOKEN contentType "application/json; charset=UTF-8" //json "${jsonbody}" json { to = ["u080859b6886c2269b28999fb9677535b"] toChannel = "1383378250" eventType = "138311608800106203" content = { contentType = "1" toType = "1" text = "HELLO I AM HERE" } } }

But when my server get the json body, it looks like below: [content:[toType:1, contentType:1], to:[u080859b6886c2269b28999fb9677535b], toChannel:1383378250, eventType:138311608800106203]

As you see, the item "content" is wrong. Besides, it loose item "text" Can you help me to solve that problem ? Thank you.

ericbai commented 9 years ago

Check the rest of your code to see if you have a variable named text. If you do, that might conflict with the word text in the DSL. If you rename your variable something else, text should show up.