lib/restful_mapper.rb in restful_mapper-0.0.1 vs lib/restful_mapper.rb in restful_mapper-0.0.2
- old
+ new
@@ -70,11 +70,11 @@
status=response.status
status_class=@response_mapping[status]
status_class||=@response_mapping[0]
body=response.body
- result=deserialize body, status_class
+ result=deserialize body, response.headers['Content-Type'], status_class
if Exception === result
raise result
end
result
end
@@ -86,18 +86,22 @@
def basic_authentication_data params
@basic_authentication.map{|name| Symbol === name ? params[name] : name}
end
- def deserialize json, mapping
- if json && !json.empty?
- mapping.from_structure(MultiJson.load(json))
- else
- if Hash == mapping || Array == mapping || mapping.is_a?(Class)
- mapping.new
+ def deserialize json, content_type, mapping
+ if content_type.start_with?('application/json')
+ if json && !json.empty?
+ mapping.from_structure(MultiJson.load(json))
else
- mapping
+ if Hash == mapping || Array == mapping || mapping.is_a?(Class)
+ mapping.new
+ else
+ mapping
+ end
end
+ else
+ mapping.from_content(content_type, json)
end
end
end