Skip to content

Commit 35368eb

Browse files
Sebastian Cohnenflori
authored andcommitted
Make json/add/[core|rails].rb respect JSON.create_id
1 parent 42a0fd5 commit 35368eb

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

lib/json/add/core.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def self.json_create(object)
2121

2222
def to_json(*args)
2323
{
24-
'json_class' => self.class.name,
24+
JSON.create_id => self.class.name,
2525
's' => tv_sec,
2626
'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
2727
}.to_json(*args)
@@ -37,7 +37,7 @@ def self.json_create(object)
3737

3838
def to_json(*args)
3939
{
40-
'json_class' => self.class.name,
40+
JSON.create_id => self.class.name,
4141
'y' => year,
4242
'm' => month,
4343
'd' => day,
@@ -63,7 +63,7 @@ def self.json_create(object)
6363

6464
def to_json(*args)
6565
{
66-
'json_class' => self.class.name,
66+
JSON.create_id => self.class.name,
6767
'y' => year,
6868
'm' => month,
6969
'd' => day,
@@ -83,7 +83,7 @@ def self.json_create(object)
8383

8484
def to_json(*args)
8585
{
86-
'json_class' => self.class.name,
86+
JSON.create_id => self.class.name,
8787
'a' => [ first, last, exclude_end? ]
8888
}.to_json(*args)
8989
end
@@ -98,7 +98,7 @@ def to_json(*args)
9898
klass = self.class.name
9999
klass.to_s.empty? and raise JSON::JSONError, "Only named structs are supported!"
100100
{
101-
'json_class' => klass,
101+
JSON.create_id => klass,
102102
'v' => values,
103103
}.to_json(*args)
104104
end
@@ -113,7 +113,7 @@ def self.json_create(object)
113113

114114
def to_json(*args)
115115
{
116-
'json_class' => self.class.name,
116+
JSON.create_id => self.class.name,
117117
'm' => message,
118118
'b' => backtrace,
119119
}.to_json(*args)
@@ -127,7 +127,7 @@ def self.json_create(object)
127127

128128
def to_json(*)
129129
{
130-
'json_class' => self.class.name,
130+
JSON.create_id => self.class.name,
131131
'o' => options,
132132
's' => source,
133133
}.to_json

lib/json/add/rails.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class Object
1010
def self.json_create(object)
1111
obj = new
1212
for key, value in object
13-
next if key == 'json_class'
13+
next if key == JSON.create_id
1414
instance_variable_set "@#{key}", value
1515
end
1616
obj
1717
end
1818

1919
def to_json(*a)
2020
result = {
21-
'json_class' => self.class.name
21+
JSON.create_id => self.class.name
2222
}
2323
instance_variables.inject(result) do |r, name|
2424
r[name[1..-1]] = instance_variable_get name

0 commit comments

Comments
 (0)