
To_json(:to_json => false) doesn't serialize complex types
Reported by Alexander Sorokin | January 12th, 2011 @ 06:52 PM
When calling to_json(:to_json=>false), I was expecting a hash
with primitive types. However, properties and
methods are pushed into the hash as is, w/o
to_json serialization. To get the true json hash, I'd have to
serialize to json and deserialize the data back:
reloaded_json = JSON.load(JSON.dump( json_representation ))
Here's a spec that captures this behavior: https://gist.github.com/777189 .
Comments and changes to this ticket
-
-
Dan Kubb (dkubb) March 23rd, 2011 @ 10:07 PM
- State changed from new to confirmed
@Alexander: I'm not entirely sure the { :to_json => false } API is documented, and I suspect it was never intended for end user usage.
There's the #as_json method which is what's called under the hood, and it is part of the documented API.
Should we change it so that we call #to_json on the attribute value here:
https://github.com/datamapper/dm-serializer/blob/master/lib/dm-seri...
In some local tests this seemed to resolve the problem you are reporting.
-
Alexander Sorokin October 8th, 2011 @ 09:53 PM
I think, calling to_json(:to_json=>false) on anything that isn't a valid json type is the right thing to do in this case.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »