Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

To_json(:to_json => false) doesn't serialize complex types #14

Open
solnic opened this issue May 17, 2011 · 2 comments
Open

To_json(:to_json => false) doesn't serialize complex types #14

solnic opened this issue May 17, 2011 · 2 comments
Labels

Comments

@solnic
Copy link
Contributor

solnic commented May 17, 2011

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 .


Created by Alexander Sorokin - 2011-01-13 00:52:08 UTC

Original Lighthouse ticket: http://datamapper.lighthouseapp.com/projects/20609/tickets/1474

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

Any thoughts on this?

by Alexander Sorokin

@solnic
Copy link
Contributor Author

solnic commented May 17, 2011

@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-serializer/to_json.rb#L31

In some local tests this seemed to resolve the problem you are reporting.

by Dan Kubb (dkubb)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant