Skip to content

Commit

Permalink
unmarshaling json is working
Browse files Browse the repository at this point in the history
  • Loading branch information
caueguerra committed Dec 9, 2009
1 parent 2c8b658 commit 4df385f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/restfulie/unmarshalling.rb
Expand Up @@ -64,13 +64,13 @@ class Base
extend Restfulie::Unmarshalling
# acts_as_jeokkarak

def self.from_json( json )
from_hash safe_json_decode( json )
def self.from_json(json)
from_hash(safe_json_decode(json).values.first)
end

# The xml has a surrounding class tag (e.g. ship-to),
# but the hash has no counterpart (e.g. 'ship_to' => {} )
def self.from_xml( xml )
def self.from_xml(xml)
hash = Hash.from_xml xml
head = hash[self.to_s.underscore]
result = self.from_hash head
Expand All @@ -82,7 +82,7 @@ def self.from_xml( xml )
end
end

def safe_json_decode( json )
def safe_json_decode(json)
return {} if !json
begin
ActiveSupport::JSON.decode json
Expand Down
2 changes: 1 addition & 1 deletion spec/client/client_spec.rb
Expand Up @@ -162,7 +162,7 @@ def mock_request_for(type, body, etag = '"ETAGVALUE"')
end

it "should deserialize correctly if its a json" do
mock_request_for "application/json", "{ status : 'CANCELLED' }"
mock_request_for "application/json", "{order: { status : 'CANCELLED' }}"

model = ClientRestfulieModel.from_web 'http://localhost:3001/order/15'
model.status.should eql("CANCELLED")
Expand Down

0 comments on commit 4df385f

Please sign in to comment.