jgritman / httpbuilder

315 stars 154 forks source link

Cannot post a json like string #45

Closed dimartiro closed 9 years ago

dimartiro commented 9 years ago

Im trying to post something like this

{ "flag": false, "data": "{a:2,b:2,c:2}" }

where the value of "data" is a string with json format but not a json object.

My problem is that when I try to request with this body, httpbuilder transforms the "data" value from string to json object and this brake the api who receives that data.

Some ideas?

Thks

dimartiro commented 9 years ago

Solved using a custom encoder

http.encoder.'application/json' = { requestData ->
            def jsonData = requestData as grails.converters.JSON 
            def entity = new org.apache.http.entity.StringEntity( (String) jsonData);
            entity.setContentType( "application/json" );
            return entity
}