-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
block format for JSONAPI::Deserializable::Resource #18
Comments
Fred, I am having the same problem and have been struggling with it for hours. In Rails (4.2.9) the received params hash has a top level :_jsonapi key and then the expected JSON:API :data key. The :_jsonapi key appears when the request's Content Type is application/vnd.api+json. After some debugging I found that it works if if you call the deserializer as follows DeserializableResourceType.call(params[:_jsonapi][:data]) This is a deserializer definition which gets all the received attributes class DeserializableObservation < JSONAPI::Deserializable::Resource
type
id
attributes
end You can whitelist the attributes too. class DeserializableObservation < JSONAPI::Deserializable::Resource
type
id
attribute :code
attribute :name
end You can get an idea of the DSL syntax here https://github.com/jsonapi-rb/jsonapi-deserializable/tree/master/spec/resource/DSL I tried with no luck to use Regards, |
Thank you for the advice Héctor! |
This clearly needs proper docs, I agree. In general, the idea is that one defines a custom deserializable resource as @hectorsq explained, using the DSL. @hectorsq could you expand on the following?
Also, the lib is currently tested against Rails 5 only, but I'd be happy to merge a PR to test it against more versions of rails. |
When I add
One thing to notice is that the payload in the params hash is contained under a Here is a fragment:
|
I've done some research and noticed that the _jsonapi key is required. I debugged my controller and the code inside the |
Anyone cal tell me the best alternative to jsonapi-rails as it clearly fails when it comes to deserialization. Serialization is also not production ready, it cannot properly serialize errors (it misses source key)? Thanks |
Valid alternatives, with their own issues: jsonapi-serializers, jsonapi-resources.
Nothing is less clear. Would you mind elaborating?
It is, it can and it doesn't.
You're welcome. |
I'm also getting I think the reason might be that the Could you please tell me if I'm missing anything here? |
Hi
I am trying to use DeserializableResourceType.call() but receiving a {} return value.
I am not sure what the format for the blocks (type, attributes, relationship and id ) in the JSONAPI::Deserializable::Resource would be.
Thank you very much
The text was updated successfully, but these errors were encountered: