summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/json/add/core.rb14
-rw-r--r--lib/json/add/rails.rb4
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/json/add/core.rb b/lib/json/add/core.rb
index 4423e7a..ae9a4df 100644
--- a/lib/json/add/core.rb
+++ b/lib/json/add/core.rb
@@ -21,7 +21,7 @@ class Time
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
's' => tv_sec,
'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
}.to_json(*args)
@@ -37,7 +37,7 @@ class Date
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'y' => year,
'm' => month,
'd' => day,
@@ -63,7 +63,7 @@ class DateTime
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'y' => year,
'm' => month,
'd' => day,
@@ -83,7 +83,7 @@ class Range
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'a' => [ first, last, exclude_end? ]
}.to_json(*args)
end
@@ -98,7 +98,7 @@ class Struct
klass = self.class.name
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
{
- 'json_class' => klass,
+ JSON.create_id => klass,
'v' => values,
}.to_json(*args)
end
@@ -113,7 +113,7 @@ class Exception
def to_json(*args)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'm' => message,
'b' => backtrace,
}.to_json(*args)
@@ -127,7 +127,7 @@ class Regexp
def to_json(*)
{
- 'json_class' => self.class.name,
+ JSON.create_id => self.class.name,
'o' => options,
's' => source,
}.to_json
diff --git a/lib/json/add/rails.rb b/lib/json/add/rails.rb
index e86ed1a..8ce85ef 100644
--- a/lib/json/add/rails.rb
+++ b/lib/json/add/rails.rb
@@ -10,7 +10,7 @@ class Object
def self.json_create(object)
obj = new
for key, value in object
- next if key == 'json_class'
+ next if key == JSON.create_id
instance_variable_set "@#{key}", value
end
obj
@@ -18,7 +18,7 @@ class Object
def to_json(*a)
result = {
- 'json_class' => self.class.name
+ JSON.create_id => self.class.name
}
instance_variables.inject(result) do |r, name|
r[name[1..-1]] = instance_variable_get name