jsonapi-deserializable
jsonapi-deserializable copied to clipboard
Adds support for included and custom deserializers
Currently, jsonapi-deserializable only adds [relationship]_id
and [relationship]_type
to the final deserialized object.
This PR enables attaching the nested document from the included section to the relationship.
Additionally, this PR adds the followings:
- Adding the document(s) from the included section of the payload is opt-in. You can enable it by adding the option
with_included: true
to the relationship. - Support for both
has_one
andhas_many
- Support for deserialization using a custom Deserializer for each relationship by passing the
deserializer:
option to the relationship. - Support for deserializing a property whose type is not the same as the property's name through the
type:
option. - Only supports first-level included if no
deserializer:
option is provided, but can support as many levels of included if the option is given. - It is backward-compatible and does not introduce breaking changes to existing code bases that use it.
See README.md for more examples
Thanks for the PR! I'll leave the decision to @remear, but in the meantime here is one remark about your third point ("Support for deserialization using a custom Deserializer for each relationship by passing the deserializer: option to the relationship."): opening the way to conflicts is not great (i.e. ending up with one resource having multiple valid deserializers), and I'd see a map from type to deserializer being used to select/customize deserializers.
My team would appreciate support for Compound Documents. @broosk1993, have you looked into the concerns brought up?
My team would appreciate support for Compound Documents. @broosk1993, have you looked into the concerns brought up?
Thank you so much @brodyhoskins. I haven't had time to address the concerns. I will try to look into them. My team will also be happy to cooperate. Let me know how you like to move forward.
@broosk1993 I'm not a maintainer unfortunately; I was only curious if you'd simply missed the comment earlier.