stas / jsonapi.rb

Lightweight, simple and maintained JSON:API support for your next Ruby HTTP API.
MIT License
261 stars 57 forks source link

add symbolize keys option to deserializer #70

Open lHydra opened 2 years ago

lHydra commented 2 years ago

What is the current behavior?

At the moment, the call to the jsonapi_deserialize method returns hash with string keys

What is the new behavior?

Method will provide new option symbolize_key which user can set to true and the returned hash will be with symbolized keys

Checklist

Please make sure the following requirements are complete:

stas commented 2 years ago

Hey hey, apologies for being late with the reviews here!

I have a couple of concerns merging this @lHydra My main ones are that symbolize_keys is part of the ActiveSupport and not generally available to folks not running rails. And you probably want deep_symbolize_keys instead, as the dict might result nested.

Another bigger concern, is that I'd prefer to leave it up to you (the end-user) to decide how to handle the parsed payload.

So if we have to change the api from (which is how it's working now):

jsonapi_deserialize(params, only: [:email]).deep_symbolize_keys

into

jsonapi_deserialize(params, symbolize_keys: true, only: [:email])

I'd prefer to keep things the way these are. I hope this makes sense.

Thank you very much for the PR though. I'm happy to discuss such concerns in the issues in future, just to avoid extra work on the PR/code. :bow: :hugs: