jsonapi-deserializable icon indicating copy to clipboard operation
jsonapi-deserializable copied to clipboard

Adds support for included and custom deserializers

Open broosk1993 opened this issue 2 years ago • 4 comments

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:

  1. 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.
  2. Support for both has_one and has_many
  3. Support for deserialization using a custom Deserializer for each relationship by passing the deserializer: option to the relationship.
  4. Support for deserializing a property whose type is not the same as the property's name through the type: option.
  5. Only supports first-level included if no deserializer: option is provided, but can support as many levels of included if the option is given.
  6. It is backward-compatible and does not introduce breaking changes to existing code bases that use it.

See README.md for more examples

broosk1993 avatar Feb 13 '23 20:02 broosk1993

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.

beauby avatar Feb 23 '23 19:02 beauby

My team would appreciate support for Compound Documents. @broosk1993, have you looked into the concerns brought up?

brodyhoskins avatar Aug 15 '24 18:08 brodyhoskins

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 avatar Aug 15 '24 19:08 broosk1993

@broosk1993 I'm not a maintainer unfortunately; I was only curious if you'd simply missed the comment earlier.

brodyhoskins avatar Aug 16 '24 04:08 brodyhoskins