json 1.8.6 → 2.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{CHANGES → CHANGES.md} +292 -96
- data/LICENSE +56 -0
- data/README.md +185 -114
- data/ext/json/ext/fbuffer/fbuffer.h +0 -3
- data/ext/json/ext/generator/generator.c +328 -117
- data/ext/json/ext/generator/generator.h +8 -8
- data/ext/json/ext/parser/extconf.rb +29 -0
- data/ext/json/ext/parser/parser.c +540 -569
- data/ext/json/ext/parser/parser.h +10 -6
- data/ext/json/ext/parser/parser.rl +269 -261
- data/ext/json/extconf.rb +1 -1
- data/json.gemspec +0 -0
- data/lib/json/add/bigdecimal.rb +40 -10
- data/lib/json/add/complex.rb +32 -9
- data/lib/json/add/core.rb +1 -0
- data/lib/json/add/date.rb +27 -7
- data/lib/json/add/date_time.rb +26 -9
- data/lib/json/add/exception.rb +25 -7
- data/lib/json/add/ostruct.rb +32 -9
- data/lib/json/add/range.rb +33 -8
- data/lib/json/add/rational.rb +30 -8
- data/lib/json/add/regexp.rb +28 -10
- data/lib/json/add/set.rb +48 -0
- data/lib/json/add/struct.rb +29 -7
- data/lib/json/add/symbol.rb +28 -5
- data/lib/json/add/time.rb +27 -6
- data/lib/json/common.rb +402 -188
- data/lib/json/ext.rb +0 -6
- data/lib/json/generic_object.rb +11 -6
- data/lib/json/pure/generator.rb +120 -137
- data/lib/json/pure/parser.rb +64 -86
- data/lib/json/pure.rb +2 -8
- data/lib/json/version.rb +2 -1
- data/lib/json.rb +559 -29
- metadata +18 -129
- data/.gitignore +0 -17
- data/.travis.yml +0 -18
- data/Gemfile +0 -7
- data/README-json-jruby.markdown +0 -33
- data/Rakefile +0 -402
- data/TODO +0 -1
- data/VERSION +0 -1
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
- data/diagrams/.keep +0 -0
- data/install.rb +0 -23
- data/java/src/json/ext/ByteListTranscoder.java +0 -166
- data/java/src/json/ext/Generator.java +0 -446
- data/java/src/json/ext/GeneratorMethods.java +0 -231
- data/java/src/json/ext/GeneratorService.java +0 -42
- data/java/src/json/ext/GeneratorState.java +0 -542
- data/java/src/json/ext/OptionsReader.java +0 -113
- data/java/src/json/ext/Parser.java +0 -2644
- data/java/src/json/ext/Parser.rl +0 -968
- data/java/src/json/ext/ParserService.java +0 -34
- data/java/src/json/ext/RuntimeInfo.java +0 -120
- data/java/src/json/ext/StringDecoder.java +0 -166
- data/java/src/json/ext/StringEncoder.java +0 -111
- data/java/src/json/ext/Utils.java +0 -88
- data/json-java.gemspec +0 -38
- data/json_pure.gemspec +0 -37
- data/lib/json/ext/.keep +0 -0
- data/tests/fixtures/fail1.json +0 -1
- data/tests/fixtures/fail10.json +0 -1
- data/tests/fixtures/fail11.json +0 -1
- data/tests/fixtures/fail12.json +0 -1
- data/tests/fixtures/fail13.json +0 -1
- data/tests/fixtures/fail14.json +0 -1
- data/tests/fixtures/fail18.json +0 -1
- data/tests/fixtures/fail19.json +0 -1
- data/tests/fixtures/fail2.json +0 -1
- data/tests/fixtures/fail20.json +0 -1
- data/tests/fixtures/fail21.json +0 -1
- data/tests/fixtures/fail22.json +0 -1
- data/tests/fixtures/fail23.json +0 -1
- data/tests/fixtures/fail24.json +0 -1
- data/tests/fixtures/fail25.json +0 -1
- data/tests/fixtures/fail27.json +0 -2
- data/tests/fixtures/fail28.json +0 -2
- data/tests/fixtures/fail3.json +0 -1
- data/tests/fixtures/fail4.json +0 -1
- data/tests/fixtures/fail5.json +0 -1
- data/tests/fixtures/fail6.json +0 -1
- data/tests/fixtures/fail7.json +0 -1
- data/tests/fixtures/fail8.json +0 -1
- data/tests/fixtures/fail9.json +0 -1
- data/tests/fixtures/pass1.json +0 -56
- data/tests/fixtures/pass15.json +0 -1
- data/tests/fixtures/pass16.json +0 -1
- data/tests/fixtures/pass17.json +0 -1
- data/tests/fixtures/pass2.json +0 -1
- data/tests/fixtures/pass26.json +0 -1
- data/tests/fixtures/pass3.json +0 -6
- data/tests/setup_variant.rb +0 -11
- data/tests/test_json.rb +0 -519
- data/tests/test_json_addition.rb +0 -196
- data/tests/test_json_encoding.rb +0 -65
- data/tests/test_json_fixtures.rb +0 -35
- data/tests/test_json_generate.rb +0 -348
- data/tests/test_json_generic_object.rb +0 -75
- data/tests/test_json_string_matching.rb +0 -39
- data/tests/test_json_unicode.rb +0 -72
- data/tools/diff.sh +0 -18
- data/tools/fuzz.rb +0 -139
- data/tools/server.rb +0 -62
@@ -1,231 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
|
3
|
-
*
|
4
|
-
* Distributed under the Ruby license: https://www.ruby-lang.org/en/about/license.txt
|
5
|
-
*/
|
6
|
-
package json.ext;
|
7
|
-
|
8
|
-
import java.lang.ref.WeakReference;
|
9
|
-
import org.jruby.Ruby;
|
10
|
-
import org.jruby.RubyArray;
|
11
|
-
import org.jruby.RubyBoolean;
|
12
|
-
import org.jruby.RubyFixnum;
|
13
|
-
import org.jruby.RubyFloat;
|
14
|
-
import org.jruby.RubyHash;
|
15
|
-
import org.jruby.RubyInteger;
|
16
|
-
import org.jruby.RubyModule;
|
17
|
-
import org.jruby.RubyNumeric;
|
18
|
-
import org.jruby.RubyString;
|
19
|
-
import org.jruby.anno.JRubyMethod;
|
20
|
-
import org.jruby.runtime.ThreadContext;
|
21
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
22
|
-
import org.jruby.util.ByteList;
|
23
|
-
|
24
|
-
/**
|
25
|
-
* A class that populates the
|
26
|
-
* <code>Json::Ext::Generator::GeneratorMethods</code> module.
|
27
|
-
*
|
28
|
-
* @author mernen
|
29
|
-
*/
|
30
|
-
class GeneratorMethods {
|
31
|
-
/**
|
32
|
-
* Populates the given module with all modules and their methods
|
33
|
-
* @param info
|
34
|
-
* @param generatorMethodsModule The module to populate
|
35
|
-
* (normally <code>JSON::Generator::GeneratorMethods</code>)
|
36
|
-
*/
|
37
|
-
static void populate(RuntimeInfo info, RubyModule module) {
|
38
|
-
defineMethods(module, "Array", RbArray.class);
|
39
|
-
defineMethods(module, "FalseClass", RbFalse.class);
|
40
|
-
defineMethods(module, "Float", RbFloat.class);
|
41
|
-
defineMethods(module, "Hash", RbHash.class);
|
42
|
-
defineMethods(module, "Integer", RbInteger.class);
|
43
|
-
defineMethods(module, "NilClass", RbNil.class);
|
44
|
-
defineMethods(module, "Object", RbObject.class);
|
45
|
-
defineMethods(module, "String", RbString.class);
|
46
|
-
defineMethods(module, "TrueClass", RbTrue.class);
|
47
|
-
|
48
|
-
info.stringExtendModule = new WeakReference<RubyModule>(module.defineModuleUnder("String")
|
49
|
-
.defineModuleUnder("Extend"));
|
50
|
-
info.stringExtendModule.get().defineAnnotatedMethods(StringExtend.class);
|
51
|
-
}
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Convenience method for defining methods on a submodule.
|
55
|
-
* @param parentModule
|
56
|
-
* @param submoduleName
|
57
|
-
* @param klass
|
58
|
-
*/
|
59
|
-
private static void defineMethods(RubyModule parentModule,
|
60
|
-
String submoduleName, Class klass) {
|
61
|
-
RubyModule submodule = parentModule.defineModuleUnder(submoduleName);
|
62
|
-
submodule.defineAnnotatedMethods(klass);
|
63
|
-
}
|
64
|
-
|
65
|
-
|
66
|
-
public static class RbHash {
|
67
|
-
@JRubyMethod(rest=true)
|
68
|
-
public static IRubyObject to_json(ThreadContext context,
|
69
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
70
|
-
return Generator.generateJson(context, (RubyHash)vSelf,
|
71
|
-
Generator.HASH_HANDLER, args);
|
72
|
-
}
|
73
|
-
}
|
74
|
-
|
75
|
-
public static class RbArray {
|
76
|
-
@JRubyMethod(rest=true)
|
77
|
-
public static IRubyObject to_json(ThreadContext context,
|
78
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
79
|
-
return Generator.generateJson(context, (RubyArray)vSelf,
|
80
|
-
Generator.ARRAY_HANDLER, args);
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
public static class RbInteger {
|
85
|
-
@JRubyMethod(rest=true)
|
86
|
-
public static IRubyObject to_json(ThreadContext context,
|
87
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
88
|
-
return Generator.generateJson(context, vSelf, args);
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
public static class RbFloat {
|
93
|
-
@JRubyMethod(rest=true)
|
94
|
-
public static IRubyObject to_json(ThreadContext context,
|
95
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
96
|
-
return Generator.generateJson(context, (RubyFloat)vSelf,
|
97
|
-
Generator.FLOAT_HANDLER, args);
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
public static class RbString {
|
102
|
-
@JRubyMethod(rest=true)
|
103
|
-
public static IRubyObject to_json(ThreadContext context,
|
104
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
105
|
-
return Generator.generateJson(context, (RubyString)vSelf,
|
106
|
-
Generator.STRING_HANDLER, args);
|
107
|
-
}
|
108
|
-
|
109
|
-
/**
|
110
|
-
* <code>{@link RubyString String}#to_json_raw(*)</code>
|
111
|
-
*
|
112
|
-
* <p>This method creates a JSON text from the result of a call to
|
113
|
-
* {@link #to_json_raw_object} of this String.
|
114
|
-
*/
|
115
|
-
@JRubyMethod(rest=true)
|
116
|
-
public static IRubyObject to_json_raw(ThreadContext context,
|
117
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
118
|
-
RubyHash obj = toJsonRawObject(context, Utils.ensureString(vSelf));
|
119
|
-
return Generator.generateJson(context, obj,
|
120
|
-
Generator.HASH_HANDLER, args);
|
121
|
-
}
|
122
|
-
|
123
|
-
/**
|
124
|
-
* <code>{@link RubyString String}#to_json_raw_object(*)</code>
|
125
|
-
*
|
126
|
-
* <p>This method creates a raw object Hash, that can be nested into
|
127
|
-
* other data structures and will be unparsed as a raw string. This
|
128
|
-
* method should be used if you want to convert raw strings to JSON
|
129
|
-
* instead of UTF-8 strings, e.g. binary data.
|
130
|
-
*/
|
131
|
-
@JRubyMethod(rest=true)
|
132
|
-
public static IRubyObject to_json_raw_object(ThreadContext context,
|
133
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
134
|
-
return toJsonRawObject(context, Utils.ensureString(vSelf));
|
135
|
-
}
|
136
|
-
|
137
|
-
private static RubyHash toJsonRawObject(ThreadContext context,
|
138
|
-
RubyString self) {
|
139
|
-
Ruby runtime = context.getRuntime();
|
140
|
-
RubyHash result = RubyHash.newHash(runtime);
|
141
|
-
|
142
|
-
IRubyObject createId = RuntimeInfo.forRuntime(runtime)
|
143
|
-
.jsonModule.get().callMethod(context, "create_id");
|
144
|
-
result.op_aset(context, createId, self.getMetaClass().to_s());
|
145
|
-
|
146
|
-
ByteList bl = self.getByteList();
|
147
|
-
byte[] uBytes = bl.unsafeBytes();
|
148
|
-
RubyArray array = runtime.newArray(bl.length());
|
149
|
-
for (int i = bl.begin(), t = bl.begin() + bl.length(); i < t; i++) {
|
150
|
-
array.store(i, runtime.newFixnum(uBytes[i] & 0xff));
|
151
|
-
}
|
152
|
-
|
153
|
-
result.op_aset(context, runtime.newString("raw"), array);
|
154
|
-
return result;
|
155
|
-
}
|
156
|
-
|
157
|
-
@JRubyMethod(required=1, module=true)
|
158
|
-
public static IRubyObject included(ThreadContext context,
|
159
|
-
IRubyObject vSelf, IRubyObject module) {
|
160
|
-
RuntimeInfo info = RuntimeInfo.forRuntime(context.getRuntime());
|
161
|
-
return module.callMethod(context, "extend", info.stringExtendModule.get());
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
public static class StringExtend {
|
166
|
-
/**
|
167
|
-
* <code>{@link RubyString String}#json_create(o)</code>
|
168
|
-
*
|
169
|
-
* <p>Raw Strings are JSON Objects (the raw bytes are stored in an
|
170
|
-
* array for the key "raw"). The Ruby String can be created by this
|
171
|
-
* module method.
|
172
|
-
*/
|
173
|
-
@JRubyMethod(required=1)
|
174
|
-
public static IRubyObject json_create(ThreadContext context,
|
175
|
-
IRubyObject vSelf, IRubyObject vHash) {
|
176
|
-
Ruby runtime = context.getRuntime();
|
177
|
-
RubyHash o = vHash.convertToHash();
|
178
|
-
IRubyObject rawData = o.fastARef(runtime.newString("raw"));
|
179
|
-
if (rawData == null) {
|
180
|
-
throw runtime.newArgumentError("\"raw\" value not defined "
|
181
|
-
+ "for encoded String");
|
182
|
-
}
|
183
|
-
RubyArray ary = Utils.ensureArray(rawData);
|
184
|
-
byte[] bytes = new byte[ary.getLength()];
|
185
|
-
for (int i = 0, t = ary.getLength(); i < t; i++) {
|
186
|
-
IRubyObject element = ary.eltInternal(i);
|
187
|
-
if (element instanceof RubyFixnum) {
|
188
|
-
bytes[i] = (byte)RubyNumeric.fix2long(element);
|
189
|
-
} else {
|
190
|
-
throw runtime.newTypeError(element, runtime.getFixnum());
|
191
|
-
}
|
192
|
-
}
|
193
|
-
return runtime.newString(new ByteList(bytes, false));
|
194
|
-
}
|
195
|
-
}
|
196
|
-
|
197
|
-
public static class RbTrue {
|
198
|
-
@JRubyMethod(rest=true)
|
199
|
-
public static IRubyObject to_json(ThreadContext context,
|
200
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
201
|
-
return Generator.generateJson(context, (RubyBoolean)vSelf,
|
202
|
-
Generator.TRUE_HANDLER, args);
|
203
|
-
}
|
204
|
-
}
|
205
|
-
|
206
|
-
public static class RbFalse {
|
207
|
-
@JRubyMethod(rest=true)
|
208
|
-
public static IRubyObject to_json(ThreadContext context,
|
209
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
210
|
-
return Generator.generateJson(context, (RubyBoolean)vSelf,
|
211
|
-
Generator.FALSE_HANDLER, args);
|
212
|
-
}
|
213
|
-
}
|
214
|
-
|
215
|
-
public static class RbNil {
|
216
|
-
@JRubyMethod(rest=true)
|
217
|
-
public static IRubyObject to_json(ThreadContext context,
|
218
|
-
IRubyObject vSelf, IRubyObject[] args) {
|
219
|
-
return Generator.generateJson(context, vSelf,
|
220
|
-
Generator.NIL_HANDLER, args);
|
221
|
-
}
|
222
|
-
}
|
223
|
-
|
224
|
-
public static class RbObject {
|
225
|
-
@JRubyMethod(rest=true)
|
226
|
-
public static IRubyObject to_json(ThreadContext context,
|
227
|
-
IRubyObject self, IRubyObject[] args) {
|
228
|
-
return RbString.to_json(context, self.asString(), args);
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* This code is copyrighted work by Daniel Luz <dev at mernen dot com>.
|
3
|
-
*
|
4
|
-
* Distributed under the Ruby license: https://www.ruby-lang.org/en/about/license.txt
|
5
|
-
*/
|
6
|
-
package json.ext;
|
7
|
-
|
8
|
-
import java.io.IOException;
|
9
|
-
import java.lang.ref.WeakReference;
|
10
|
-
|
11
|
-
import org.jruby.Ruby;
|
12
|
-
import org.jruby.RubyClass;
|
13
|
-
import org.jruby.RubyModule;
|
14
|
-
import org.jruby.runtime.load.BasicLibraryService;
|
15
|
-
|
16
|
-
/**
|
17
|
-
* The service invoked by JRuby's {@link org.jruby.runtime.load.LoadService LoadService}.
|
18
|
-
* Defines the <code>JSON::Ext::Generator</code> module.
|
19
|
-
* @author mernen
|
20
|
-
*/
|
21
|
-
public class GeneratorService implements BasicLibraryService {
|
22
|
-
public boolean basicLoad(Ruby runtime) throws IOException {
|
23
|
-
runtime.getLoadService().require("json/common");
|
24
|
-
RuntimeInfo info = RuntimeInfo.initRuntime(runtime);
|
25
|
-
|
26
|
-
info.jsonModule = new WeakReference<RubyModule>(runtime.defineModule("JSON"));
|
27
|
-
RubyModule jsonExtModule = info.jsonModule.get().defineModuleUnder("Ext");
|
28
|
-
RubyModule generatorModule = jsonExtModule.defineModuleUnder("Generator");
|
29
|
-
|
30
|
-
RubyClass stateClass =
|
31
|
-
generatorModule.defineClassUnder("State", runtime.getObject(),
|
32
|
-
GeneratorState.ALLOCATOR);
|
33
|
-
stateClass.defineAnnotatedMethods(GeneratorState.class);
|
34
|
-
info.generatorStateClass = new WeakReference<RubyClass>(stateClass);
|
35
|
-
|
36
|
-
RubyModule generatorMethods =
|
37
|
-
generatorModule.defineModuleUnder("GeneratorMethods");
|
38
|
-
GeneratorMethods.populate(info, generatorMethods);
|
39
|
-
|
40
|
-
return true;
|
41
|
-
}
|
42
|
-
}
|