json 2.0.3 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGES.md +66 -0
- data/Gemfile +1 -3
- data/LICENSE +56 -0
- data/README.md +54 -21
- data/VERSION +1 -1
- data/ext/json/ext/fbuffer/fbuffer.h +0 -3
- data/ext/json/ext/generator/generator.c +229 -54
- data/ext/json/ext/generator/generator.h +5 -3
- data/ext/json/ext/parser/extconf.rb +25 -0
- data/ext/json/ext/parser/parser.c +180 -85
- data/ext/json/ext/parser/parser.h +2 -0
- data/ext/json/ext/parser/parser.rl +104 -9
- data/ext/json/extconf.rb +1 -0
- data/json.gemspec +0 -0
- data/lib/json/add/bigdecimal.rb +2 -2
- data/lib/json/add/complex.rb +2 -3
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/rational.rb +2 -3
- data/lib/json/add/regexp.rb +2 -2
- data/lib/json/add/set.rb +29 -0
- data/lib/json/common.rb +372 -125
- data/lib/json/pure/generator.rb +31 -10
- data/lib/json/pure/parser.rb +35 -5
- data/lib/json/version.rb +1 -1
- data/lib/json.rb +549 -29
- data/tests/fixtures/fail29.json +1 -0
- data/tests/fixtures/fail30.json +1 -0
- data/tests/fixtures/fail31.json +1 -0
- data/tests/fixtures/fail32.json +1 -0
- data/tests/json_addition_test.rb +6 -0
- data/tests/json_common_interface_test.rb +47 -4
- data/tests/json_encoding_test.rb +2 -0
- data/tests/json_fixtures_test.rb +9 -1
- data/tests/json_generator_test.rb +30 -8
- data/tests/json_parser_test.rb +43 -12
- data/tests/lib/core_assertions.rb +763 -0
- data/tests/lib/envutil.rb +365 -0
- data/tests/lib/find_executable.rb +22 -0
- data/tests/lib/helper.rb +4 -0
- data/tests/ractor_test.rb +30 -0
- data/tests/test_helper.rb +3 -7
- metadata +31 -44
- data/.gitignore +0 -17
- data/.travis.yml +0 -19
- data/README-json-jruby.md +0 -33
- data/Rakefile +0 -408
- 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 -443
- 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 -490
- data/java/src/json/ext/OptionsReader.java +0 -113
- data/java/src/json/ext/Parser.java +0 -2347
- data/java/src/json/ext/Parser.rl +0 -878
- data/java/src/json/ext/ParserService.java +0 -34
- data/java/src/json/ext/RuntimeInfo.java +0 -116
- 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 -38
- data/references/rfc7159.txt +0 -899
- data/tools/diff.sh +0 -18
- data/tools/fuzz.rb +0 -131
- 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
|
-
}
|