jsonj-integration 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/jsonj.rb +53 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODM5ZmI2NTU2MGQ4N2ZhMjAzNzBhYmVjMGZhYjVmMWRkNDNhODQzNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2IxNDAzODZiMWI2MjIwMjM3NGIwYTkzNDgzYzI4MDdmZWYxMDQ0Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTc1Y2FmNjNlZGZjMDI5OTQ1ZTU3YzYwZDY3M2U0NGE4MzhhYzZhNzAyMTJk
|
10
|
+
NjMzNmZkYmE5YzJhMDM1YzYxNThkZjVhYTQ2YTVlMzhiMzFjMWViMDU0ODhm
|
11
|
+
N2E1NDQ1MzU0MTU4MGJkNWM0YzcxMTFiM2RiMDM0ZjI4M2Q3N2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTMyMGE1MWYyODFhMTU4MDA1NTgxMzgwZmE4MDBkN2ViNTkzNDFmMDA3NmJi
|
14
|
+
MzM1Y2RlYTdjODNlNWNjNWU1ZDk4NGYxODk3ODVkMzM1YWM2YzRkMGYzODk4
|
15
|
+
ODZhNzhjY2I5ZjI0MTNkZTk5YzcwZmVlZDIxYWJlNmY5OTMwMWM=
|
data/lib/jsonj.rb
CHANGED
@@ -8,10 +8,12 @@
|
|
8
8
|
#
|
9
9
|
java_import com.github.jsonj.JsonObject
|
10
10
|
java_import com.github.jsonj.JsonArray
|
11
|
+
java_import com.github.jsonj.JsonSet
|
11
12
|
java_import com.github.jsonj.JsonPrimitive
|
12
13
|
java_import com.github.jsonj.JsonType
|
13
14
|
java_import com.github.jsonj.tools.JsonBuilder
|
14
15
|
|
16
|
+
|
15
17
|
# this function is injected into JsonElement subclasses
|
16
18
|
def convertToRuby(value)
|
17
19
|
if value.isObject
|
@@ -48,10 +50,31 @@ JsonArray.send(:define_method, 'to_s') do
|
|
48
50
|
tos self
|
49
51
|
end
|
50
52
|
|
53
|
+
JsonSet.send(:define_method, 'to_s') do
|
54
|
+
tos self
|
55
|
+
end
|
56
|
+
|
51
57
|
JsonPrimitive.send(:define_method, 'to_s') do
|
52
58
|
tos self
|
53
59
|
end
|
54
60
|
|
61
|
+
JsonObject.send(:define_method, 'to_json') do
|
62
|
+
tos self
|
63
|
+
end
|
64
|
+
|
65
|
+
JsonArray.send(:define_method, 'to_json') do
|
66
|
+
tos self
|
67
|
+
end
|
68
|
+
|
69
|
+
JsonSet.send(:define_method, 'to_json') do
|
70
|
+
tos self
|
71
|
+
end
|
72
|
+
|
73
|
+
JsonPrimitive.send(:define_method, 'to_json') do
|
74
|
+
tos self
|
75
|
+
end
|
76
|
+
|
77
|
+
|
55
78
|
JsonObject.send(:define_method, 'toRuby') do
|
56
79
|
convertToRuby self
|
57
80
|
end
|
@@ -60,7 +83,6 @@ JsonObject.send(:define_method, '[]=') do |key,value|
|
|
60
83
|
self.put(key.to_s,JsonBuilder::fromObject(value))
|
61
84
|
end
|
62
85
|
|
63
|
-
|
64
86
|
JsonObject.send(:define_method, '[]') do |key|
|
65
87
|
val = self.get(key)
|
66
88
|
if val && val.isPrimitive
|
@@ -97,18 +119,48 @@ JsonArray.send(:define_method, '[]') do |key|
|
|
97
119
|
end
|
98
120
|
end
|
99
121
|
|
122
|
+
JsonSet.send(:define_method, '[]') do |key|
|
123
|
+
val = self.get(key)
|
124
|
+
if val && val.isPrimitive
|
125
|
+
case val.type.to_s
|
126
|
+
when 'string'
|
127
|
+
val.asString
|
128
|
+
when 'number'
|
129
|
+
val.asDouble
|
130
|
+
when 'bool'
|
131
|
+
val.asBoolean
|
132
|
+
when 'nullValue'
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
else
|
136
|
+
val
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
100
140
|
JsonArray.send(:define_method, '[]=') do |index,value|
|
101
141
|
self.set(index,JsonBuilder::fromObject(value))
|
102
142
|
end
|
103
143
|
|
144
|
+
JsonSet.send(:define_method, '[]=') do |index,value|
|
145
|
+
self.set(index,JsonBuilder::fromObject(value))
|
146
|
+
end
|
147
|
+
|
104
148
|
JsonArray.send(:define_method, '<<') do |value|
|
105
149
|
self.add(JsonBuilder::fromObject(value))
|
106
150
|
end
|
107
151
|
|
152
|
+
JsonSet.send(:define_method, '<<') do |value|
|
153
|
+
self.add(JsonBuilder::fromObject(value))
|
154
|
+
end
|
155
|
+
|
108
156
|
JsonArray.send(:define_method, 'toRuby') do
|
109
157
|
convertToRuby self
|
110
158
|
end
|
111
159
|
|
160
|
+
JsonSet.send(:define_method, 'toRuby') do
|
161
|
+
convertToRuby self
|
162
|
+
end
|
163
|
+
|
112
164
|
JsonPrimitive.send(:define_method, 'toRuby') do
|
113
165
|
if(self.type.toString == 'string')
|
114
166
|
self.asString
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonj-integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jilles van Gurp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides seemless integration of the jsonj library by adding conversion methods to hashes, lists and JsonElement instances and support for using [] and << on the Java objects.
|
14
14
|
email: incoming@jillesvangurp.xom
|