Commit Graph

37 Commits

Author SHA1 Message Date
Corin Langosch
295bf413e5 add missing require for ordered_hash dependency 2011-05-11 16:22:35 +02:00
John Firebaugh
080e2a7abf Enumerable should pass encoding options to children in #as_json/#to_json. 2011-04-01 12:16:54 -07:00
Josh Kalderimis
e8c870726a Updated the json date regex to recognize xmlschema formatted date times during json decoding. [#3031 state:resolved]
Signed-off-by: Santiago Pastorino and Emilio Tagua <santiago+emilioe@wyeworks.com>
2011-02-12 13:30:30 -02:00
Alexey Nayden
a9163b547c Complex struct encoding fix
[#6077 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2011-01-15 00:06:26 -02:00
Emilio Tagua
7047d83ec5 Perf: speed up json encoding.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
2010-09-22 18:08:04 -03:00
Jakub Suder
2524cf404c fixed some issues with JSON encoding
- as_json in ActiveModel should return a hash
  and handle :only/:except/:methods options
- Array and Hash should call as_json on their elements
- json methods should not modify options argument

[#5374 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-09-07 11:33:10 -07:00
Santiago Pastorino
5bf3294c8b Move Date#xmlschema to conversions and add a missing require 2010-07-04 14:10:28 -07:00
Santiago Pastorino
8cc746331c Time#formatted_offset is defined in core_ext/time/conversions
[#4979]
2010-07-02 20:22:35 -07:00
Geoff Buesing
227e1caea5 Time#as_json: use Time#formatted_offset instead of strftime %z directive, which is non-standard and inaccurate on some platforms (e.g., Mac OS X).
[#4979]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2010-07-02 11:50:16 -07:00
Santiago Pastorino
cb321546b7 Time has it own implementation of xmlschema, now AMo doesn't depend on TZInfo
[#4979 state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
2010-07-02 01:51:03 +02:00
Santiago Pastorino
4a0c514eb4 AS json refactor, move to_json implementation to core_ext and a cleanup a bit the code 2010-07-01 12:04:11 -07:00
José Valim
7bd85a8fc2 Work around the fact the JSON gem was overwriting to_json implementation for all Ruby core classes.
This is required because the JSON gem is incompatible with Rails behavior and was not allowing ActiveModel::Errors to be serialized.
So we need to ensure Rails implementation is the one triggered. [#4890 state:resolved]
2010-06-26 12:01:13 +02:00
Xavier Noria
9e085a9f33 adds a comment explaining why BigDecimal#as_json returns a JSON string 2010-05-03 22:04:47 +02:00
Santiago Pastorino
02028e529c Missing require added make pass activesupport/test/json/encoding_test.rb in isolation
Signed-off-by: Xavier Noria <fxn@hashref.com>
2010-05-02 22:05:40 +02:00
Xavier Noria
1d63129eff use ordinary syntax for options to be well-formed in 1.8 2010-04-27 02:36:34 -07:00
Jeremy Kemper
c1d7327071 JSON: encode objects that don't have a native JSON representation using to_hash, if available, instead of instance_values (the old fallback) or to_s (other encoders' default). Encode BigDecimal and Regexp encode as strings to conform with other encoders. Try to transcode non-UTF-8 strings. 2010-04-26 19:55:39 -07:00
David Heinemeier Hansson
6042067c0b Changed the default ActiveSupport.use_standard_json_time_format from false to true and
ActiveSupport.escape_html_entities_in_json from true to false to match previously announced Rails 3 defaults [DHH]
2010-01-03 19:20:43 -08:00
Dwayne Litzenberger
808cad2bb4 Fix ActiveSupport::JSON encoding of control characters [\x00-\x1f]
According to RFC 4627, only the following Unicode code points are
allowed unescaped in JSON:

  unescaped = %x20-21 / %x23-5B / %x5D-10FFFF

However, ActiveSupport::JSON did not escape the range %x00-1f.  This caused
parse errors when trying to decode the resulting output.

[#3345 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
2009-12-23 11:46:06 -08:00
Jeremy Kemper
bc1538e995 Repair time dependencies 2009-11-14 11:37:06 -08:00
Jeremy Kemper
36a9644b86 Clarify date/time dependencies 2009-11-02 17:50:12 -08:00
Jeremy Kemper
49824e8ad6 JSON.escape returns UTF-8 strings
[#2849 state:resolved]
2009-07-01 16:22:19 -07:00
Jeremy Kemper
f37a2ea84c uses Hash#except/slice 2009-07-01 16:01:20 -07:00
Joshua Peek
fbdf706fff Add basic JSON serializer to AMo 2009-06-17 21:27:54 -05:00
Jeremy Kemper
30a3b6b4fc Ruby 1.9: fix json encoding 2009-06-08 15:16:47 -07:00
Jeremy Kemper
00ee990443 JSON: split encoding and coercion 2009-06-08 13:21:30 -07:00
Jeremy Kemper
f58c322e7e Use __send__ for BasicObject friendliness 2009-04-26 20:05:17 -07:00
Jeremy Kemper
ee46ffedb8 Now that we have a separate internal rails_to_json, use a separate circular reference stack instead of sticking it in the options hash 2009-04-26 20:04:47 -07:00
Jeremy Kemper
8d64085138 Only Object to_json alias is needed. Prefer nil options. 2009-04-26 15:18:33 -07:00
Jeremy Kemper
da3a80dd4f Track object ids so the objects needn't respond to == 2009-04-26 15:04:02 -07:00
rick
3c4c6bd0df * Add pluggable JSON backends with support for the JSON gem. [rick]
Example: ActiveSupport::JSON.backend = "JSONGem"

  All internal Rails JSON encoding is now handled by ActiveSupport::JSON.encode().  Use of #to_json is not recommended, as it may clash with other libraries that overwrite it.  However, you can recover Rails specific functionality
  if you really want to use #to_json.

    gem 'json'
    ActiveSupport::JSON.backend = "JSONGem"

    class ActiveRecord::Base
      alias to_json rails_to_json
    end
2009-04-23 00:08:40 -07:00
Jeremy Kemper
6599dd907f Simpler and clearer to just explicitly require the JSON encoders 2008-11-26 01:08:37 -08:00
Jeremy Kemper
e9aa975cc9 Eliminate thread-local circular reference stack by passing it as an argument instead 2008-11-23 12:36:03 -08:00
Rick Olson
605196c448 Add config.active_support.escape_html_entities_in_json to allow disabling of html entity escaping. [rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9238 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2008-04-08 03:45:26 +00:00
Jeremy Kemper
b1968708e1 Hash#to_json takes :only or :except options to specific or omit certain hash keys. Enumerable#to_json passes through its options to each element. Closes #9751.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7736 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-10-04 03:28:42 +00:00
David Heinemeier Hansson
7275d2749c Fixed JSON encoding to use quoted keys according to the JSON standard (closes #8762) [choonkat/chuyeow]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7697 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-09-30 20:57:50 +00:00
Jeremy Kemper
d2acf8b548 Silence some warnings.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6772 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-05-18 21:16:43 +00:00
Sam Stephenson
3202fbabe6 Refactor ActiveSupport::JSON to be less obtuse. Add support for JSON decoding by way of Syck with ActiveSupport::JSON.decode(json_string). Prevent hash keys that are JavaScript reserved words from being unquoted during encoding.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6443 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
2007-03-18 07:05:58 +00:00