1 # This file contains implementations of rails custom objects for
2 # serialisation/deserialisation.
4 unless Object.const_defined?(:JSON) and ::JSON.const_defined?(:JSON_LOADED) and
10 def self.json_create(object)
12 for key, value in object
13 next if key == 'json_class'
14 instance_variable_set "@#{key}", value
21 'json_class' => self.class.name
23 instance_variables.inject(result) do |r, name|
24 r[name[1..-1]] = instance_variable_get name
49 # The above rails definition has some problems:
51 # 1. { 'foo' => /bar/ }.to_json # => "{foo: /bar/}"
52 # This isn't valid JSON, because the regular expression syntax is not
53 # defined in RFC 4627. (And unquoted strings are disallowed there, too.)
54 # Though it is valid Javascript.
56 # 2. { 'foo' => /bar/mix }.to_json # => "{foo: /bar/mix}"
57 # This isn't even valid Javascript.