jsonapi-rb / jsonapi-rails

Rails gem for fast jsonapi-compliant APIs.
http://jsonapi-rb.org
MIT License
318 stars 62 forks source link

Deserializing resources fails, not sure why, code has a todo about a more helpful error #103

Closed bsylvain closed 5 years ago

bsylvain commented 5 years ago

WHen I use deseriable_recource :reply_post in my controller here is the error I get :

undefined method `to_unsafe_hash' for nil:NilClass
Extracted source (around line #72):

#70             # TODO(lucas): Fail with helpful error message if _jsonapi not
#71             #   present.
*72             hash = controller.params[:_jsonapi].to_unsafe_hash
#73             ActiveSupport::Notifications
#74               .instrument('parse.jsonapi', payload: hash, class: klass) do
#75               JSONAPI::Parser::Resource.parse!(hash)

If I remove the method, params is the usual hash : <ActionController::Parameters {"data"=>{"attributes"=>{"reply"=>nil, "invisible-to-user"=>false, "created-at"=>nil}, "relationships"=>{"ticket"=>{"data"=>{"type"=>"tickets", "id"=>"65"}}}, "type"=>"ticket/replies"}, "controller"=>"marketadmin_api/v1/ticket/replies", "action"=>"create"} permitted: false>

Despite the request being a application/vnd.api+json with the following content : {"data":{"attributes":{"reply":null,"invisible-to-user":false,"created-at":null},"relationships":{"ticket":{"data":{"type":"tickets","id":"65"}}},"type":"ticket/replies"}}

Why is JSONAPI-RB trying to find _jsonapi in the params ?

bsylvain commented 5 years ago

I am migrating from AMS to jsonapi-rb and the PARSER in railties is replaced by one from AMS. I'll use AMS as deserializer until I remove it