-
Notifications
You must be signed in to change notification settings - Fork 899
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
A JSON serializer should be included by default #194
Comments
I thought about this when I put together the custom serializer code and my conclusion was that changing the serializer was a really uncommon use-case. My original usecase was to serialize the object_changes into an hstore for Postgres, but on further investigation, it doesn't really quite work straight out of the box as the hash values are all arrays. Having the keys usable is still useful though. I'd love to hear more usecases, particularly for a JSON serializer. Would we save space by using JSON over YML? |
Surprisingly, using JSON over YAML doesn't seem to save space. The strings generated from a JSON dump generally tend to be a bit longer (unless the hash is tiny) due to all the internal quotation marks used in JSON strings. One argument for the case of providing a JSON parser is the confusion surrounding the fact that Ruby 1.9.2 and 1.9.3 provide two different YAML parsers that behave slightly differently. Due to the confusion that results from this, some users may wish to avoid YAML entirely. Personally, I haven't run into any issues, but I am confused about what scenario's it still makes sense to use I feel this is a legitimate argument for providing a JSON serializer. |
ActiveSupport::JSON vs JSON gemUsing
JSON vs YAMLThe primary reasons I usually pick JSON over YAML are:
|
Thanks a lot for the thoughtful response! Those are all good reasons that make a better case for I poked around in the I also agree that a bit of space saved in the DB is not a huge concern, especially when serializing/deserializing are much faster (not to mention the other reasons you prefer JSON). These all seem like reasons enough for me (to warrant inclusion of JSON serializer in the gem by default)! |
That's interesting... I didn't realize ActiveSupport::JSON wasn't using MultiJson to serialize to JSON. I'm not sure what the reason is, but I'm sure the history of it must be convoluted. :) |
Here is roughly what it would look like:
Or
@dwbutler - Can you elaborate a bit more on what you mean when you say "It's also more portable (for example, it will automagically pick up MultiJSON.)"? I don't see ActiveSupport::JSON listed as one of the supported JSON engines for MultiJSON (JSON is though). Just curious as to what you think the pro's and con's are of using ActiveSupport::JSON vs. the default JSON gem?
Perhaps it makes sense to just bundle MultiJSON into the library, although, I'm a bit weary of doing that when this will not be the default parser for PaperTrail (at least for now).
The text was updated successfully, but these errors were encountered: