[Rails-core] A minor beef with JSON::decode

2012-07-25 Thread Josh Bourgeois
Hiya,

So, what was the impetus behind having ParamsParser create Date and 
DateTime objects out of application/json requests?  The project I'm on 
expects parameters to be received as standard types (bools, numbers, 
strings, arrays, and hashes).  Rails shouldn't try to convert objects that 
are explicitly passed as these types; it should be up to the application to 
do that.

example:

JSON
request_parameters:{foo:2012-05-12}

Should get to our controller as
params[:foo] = 2012-05-12

But instead comes in as
params[:foo] = Date:0x2af5607

-- 
You received this message because you are subscribed to the Google Groups Ruby 
on Rails: Core group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/X6I3c0vSGrUJ.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.



Re: [Rails-core] A minor beef with JSON::decode

2012-07-25 Thread Aaron Patterson
On Wed, Jul 25, 2012 at 11:09:06AM -0700, Josh Bourgeois wrote:
 Hiya,
 
 So, what was the impetus behind having ParamsParser create Date and 
 DateTime objects out of application/json requests?  The project I'm on 
 expects parameters to be received as standard types (bools, numbers, 
 strings, arrays, and hashes).  Rails shouldn't try to convert objects that 
 are explicitly passed as these types; it should be up to the application to 
 do that.

I think this ship has sailed. :-/

However, it looks like you can set ActiveSupport.parse_json_times to
false:

  
https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/json/decoding.rb#L6-7

And it won't try to parse dates:

  
https://github.com/rails/rails/blob/3-2-stable/activesupport/lib/active_support/json/decoding.rb#L19-23

-- 
Aaron Patterson
http://tenderlovemaking.com/


pgppbhKW2vSpP.pgp
Description: PGP signature