Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTParty double escapes my json
    primarykey
    data
    text
    <p>I have a few models in Ruby that I need to send to a Java/RestEasy server via HTTParty/Put.</p> <p>configuration_mapping.rb:</p> <pre><code>def as_json(options = {}) {:configGroup =&gt; @group, :coordinates =&gt; {@key =&gt; @value}} end def self.put(endpoint, content, tier = 'nursery') response = HTTParty.put(base_uri + endpoint, json_payload(content)) end def self.json_payload(content) { :body =&gt; content.to_json, :format =&gt; :json, :headers =&gt; {"Content-Type" =&gt; "application/json", "content-type" =&gt; "application/json", "Accept" =&gt; "application/json"} } end </code></pre> <p><strong>The JSON gets double escaped:</strong></p> <blockquote> <p>{ :body=>" { \"configGroup\":\"test\", \"coordinates\":{ \"Integration Test Key\":\"moo\" } } ", :format=>:json, :headers=>{" Content-Type"=>"application/json", "content-type"<br> =>"application/json", "Accept" =>"application/json" } }</p> </blockquote> <p>And Jackson JSON parser borks:</p> <blockquote> <p>2011-11-27 15:34:11,179 ERROR [tp-1442358158-0] [REPORT] [] [asy.core.SynchronousDispatcher] Failed executing PUT /v1/groups/test/mappings;tester=Integration Test;tier=qa;timeStamp=-4712-01-01 org.jboss.resteasy.spi.ReaderException: org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token at [Source: org.mortbay.jetty.HttpParser$Input@4092fef5; line: 1, column: 22] at</p> </blockquote> <p>I tried letting httparty convert to json for me, thinking httparty escaped the characters, writing my own as_json method, but this is the output which is not the json I wanted, the wrong fields are in here and my as_json method is not called:</p> <blockquote> <p>{:body=>Config::Client::ConfigurationMapping:0x00000100c78930 @dimensions={"tester"=>"Integration Test", "tier"=>"qa", "timeStamp"=>"-4712-01-01"}, @key="Integration Test Key", @group="test", @value="moo">, :format=>:json, :headers=>{"Content-Type"=>"application/json", "content-type"=>"application/json", "Accept"=>"application/json"}}</p> </blockquote> <p>What is causing the string to become double escaped?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload