json 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +9 -4
- data/CHANGES.md +3 -0
- data/Gemfile +0 -2
- data/LICENSE +56 -0
- data/README.md +38 -21
- data/Rakefile +10 -5
- data/VERSION +1 -1
- data/ext/json/ext/generator/generator.c +96 -40
- data/ext/json/ext/parser/parser.c +106 -79
- data/ext/json/ext/parser/parser.rl +33 -6
- data/java/src/json/ext/Generator.java +33 -10
- data/java/src/json/ext/Parser.java +3 -3
- data/java/src/json/ext/Parser.rl +1 -1
- data/json-java.gemspec +1 -2
- data/json.gemspec +0 -0
- data/json_pure.gemspec +5 -5
- data/lib/json/add/bigdecimal.rb +2 -2
- data/lib/json/add/complex.rb +2 -2
- data/lib/json/add/ostruct.rb +1 -1
- data/lib/json/add/rational.rb +2 -2
- data/lib/json/add/regexp.rb +2 -2
- data/lib/json/add/set.rb +29 -0
- data/lib/json/common.rb +2 -2
- data/lib/json/pure/generator.rb +2 -1
- data/lib/json/pure/parser.rb +9 -1
- data/lib/json/version.rb +1 -1
- data/tests/json_addition_test.rb +10 -0
- data/tests/json_common_interface_test.rb +4 -4
- data/tests/json_generator_test.rb +44 -0
- data/tests/json_parser_test.rb +15 -14
- data/tests/test_helper.rb +0 -4
- metadata +5 -7
- data/data/example.json +0 -1
- data/data/index.html +0 -38
- data/data/prototype.js +0 -4184
@@ -25,7 +25,7 @@ enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
|
|
25
25
|
|
26
26
|
/* unicode */
|
27
27
|
|
28
|
-
static const char digit_values[256] = {
|
28
|
+
static const signed char digit_values[256] = {
|
29
29
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
30
30
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
31
31
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1,
|
@@ -44,7 +44,7 @@ static const char digit_values[256] = {
|
|
44
44
|
|
45
45
|
static UTF32 unescape_unicode(const unsigned char *p)
|
46
46
|
{
|
47
|
-
char b;
|
47
|
+
signed char b;
|
48
48
|
UTF32 result = 0;
|
49
49
|
b = digit_values[p[0]];
|
50
50
|
if (b < 0) return UNI_REPLACEMENT_CHAR;
|
@@ -89,12 +89,13 @@ static int convert_UTF32_to_UTF8(char *buf, UTF32 ch)
|
|
89
89
|
|
90
90
|
static VALUE mJSON, mExt, cParser, eParserError, eNestingError;
|
91
91
|
static VALUE CNaN, CInfinity, CMinusInfinity;
|
92
|
+
static VALUE cBigDecimal = Qundef;
|
92
93
|
|
93
94
|
static ID i_json_creatable_p, i_json_create, i_create_id, i_create_additions,
|
94
95
|
i_chr, i_max_nesting, i_allow_nan, i_symbolize_names,
|
95
96
|
i_object_class, i_array_class, i_decimal_class, i_key_p,
|
96
97
|
i_deep_const_get, i_match, i_match_string, i_aset, i_aref,
|
97
|
-
i_leftshift, i_new;
|
98
|
+
i_leftshift, i_new, i_BigDecimal;
|
98
99
|
|
99
100
|
%%{
|
100
101
|
machine JSON_common;
|
@@ -339,6 +340,19 @@ static char *JSON_parse_integer(JSON_Parser *json, char *p, char *pe, VALUE *res
|
|
339
340
|
) (^[0-9Ee.\-]? @exit );
|
340
341
|
}%%
|
341
342
|
|
343
|
+
static int is_bigdecimal_class(VALUE obj)
|
344
|
+
{
|
345
|
+
if (cBigDecimal == Qundef) {
|
346
|
+
if (rb_const_defined(rb_cObject, i_BigDecimal)) {
|
347
|
+
cBigDecimal = rb_const_get_at(rb_cObject, i_BigDecimal);
|
348
|
+
}
|
349
|
+
else {
|
350
|
+
return 0;
|
351
|
+
}
|
352
|
+
}
|
353
|
+
return obj == cBigDecimal;
|
354
|
+
}
|
355
|
+
|
342
356
|
static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *result)
|
343
357
|
{
|
344
358
|
int cs = EVIL;
|
@@ -357,7 +371,11 @@ static char *JSON_parse_float(JSON_Parser *json, char *p, char *pe, VALUE *resul
|
|
357
371
|
} else {
|
358
372
|
VALUE text;
|
359
373
|
text = rb_str_new2(FBUFFER_PTR(json->fbuffer));
|
360
|
-
|
374
|
+
if (is_bigdecimal_class(json->decimal_class)) {
|
375
|
+
*result = rb_funcall(Qnil, i_BigDecimal, 1, text);
|
376
|
+
} else {
|
377
|
+
*result = rb_funcall(json->decimal_class, i_new, 1, text);
|
378
|
+
}
|
361
379
|
}
|
362
380
|
return p + 1;
|
363
381
|
} else {
|
@@ -553,7 +571,7 @@ static char *JSON_parse_string(JSON_Parser *json, char *p, char *pe, VALUE *resu
|
|
553
571
|
|
554
572
|
if (json->symbolize_names && json->parsing_name) {
|
555
573
|
*result = rb_str_intern(*result);
|
556
|
-
} else {
|
574
|
+
} else if (RB_TYPE_P(*result, T_STRING)) {
|
557
575
|
rb_str_resize(*result, RSTRING_LEN(*result));
|
558
576
|
}
|
559
577
|
if (cs >= JSON_string_first_final) {
|
@@ -710,7 +728,7 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self)
|
|
710
728
|
} else {
|
711
729
|
json->max_nesting = 100;
|
712
730
|
json->allow_nan = 0;
|
713
|
-
json->create_additions =
|
731
|
+
json->create_additions = 0;
|
714
732
|
json->create_id = rb_funcall(mJSON, i_create_id, 0);
|
715
733
|
json->object_class = Qnil;
|
716
734
|
json->array_class = Qnil;
|
@@ -824,20 +842,28 @@ static VALUE cParser_source(VALUE self)
|
|
824
842
|
|
825
843
|
void Init_parser(void)
|
826
844
|
{
|
845
|
+
#undef rb_intern
|
827
846
|
rb_require("json/common");
|
828
847
|
mJSON = rb_define_module("JSON");
|
829
848
|
mExt = rb_define_module_under(mJSON, "Ext");
|
830
849
|
cParser = rb_define_class_under(mExt, "Parser", rb_cObject);
|
831
850
|
eParserError = rb_path2class("JSON::ParserError");
|
832
851
|
eNestingError = rb_path2class("JSON::NestingError");
|
852
|
+
rb_gc_register_mark_object(eParserError);
|
853
|
+
rb_gc_register_mark_object(eNestingError);
|
833
854
|
rb_define_alloc_func(cParser, cJSON_parser_s_allocate);
|
834
855
|
rb_define_method(cParser, "initialize", cParser_initialize, -1);
|
835
856
|
rb_define_method(cParser, "parse", cParser_parse, 0);
|
836
857
|
rb_define_method(cParser, "source", cParser_source, 0);
|
837
858
|
|
838
859
|
CNaN = rb_const_get(mJSON, rb_intern("NaN"));
|
860
|
+
rb_gc_register_mark_object(CNaN);
|
861
|
+
|
839
862
|
CInfinity = rb_const_get(mJSON, rb_intern("Infinity"));
|
863
|
+
rb_gc_register_mark_object(CInfinity);
|
864
|
+
|
840
865
|
CMinusInfinity = rb_const_get(mJSON, rb_intern("MinusInfinity"));
|
866
|
+
rb_gc_register_mark_object(CMinusInfinity);
|
841
867
|
|
842
868
|
i_json_creatable_p = rb_intern("json_creatable?");
|
843
869
|
i_json_create = rb_intern("json_create");
|
@@ -858,6 +884,7 @@ void Init_parser(void)
|
|
858
884
|
i_aref = rb_intern("[]");
|
859
885
|
i_leftshift = rb_intern("<<");
|
860
886
|
i_new = rb_intern("new");
|
887
|
+
i_BigDecimal = rb_intern("BigDecimal");
|
861
888
|
}
|
862
889
|
|
863
890
|
/*
|
@@ -7,6 +7,7 @@ package json.ext;
|
|
7
7
|
|
8
8
|
import org.jruby.Ruby;
|
9
9
|
import org.jruby.RubyArray;
|
10
|
+
import org.jruby.RubyBasicObject;
|
10
11
|
import org.jruby.RubyBignum;
|
11
12
|
import org.jruby.RubyBoolean;
|
12
13
|
import org.jruby.RubyClass;
|
@@ -15,6 +16,7 @@ import org.jruby.RubyFloat;
|
|
15
16
|
import org.jruby.RubyHash;
|
16
17
|
import org.jruby.RubyNumeric;
|
17
18
|
import org.jruby.RubyString;
|
19
|
+
import org.jruby.runtime.ClassIndex;
|
18
20
|
import org.jruby.runtime.ThreadContext;
|
19
21
|
import org.jruby.runtime.builtin.IRubyObject;
|
20
22
|
import org.jruby.util.ByteList;
|
@@ -57,6 +59,19 @@ public final class Generator {
|
|
57
59
|
return handler.generateNew(session, object);
|
58
60
|
}
|
59
61
|
|
62
|
+
// NOTE: drop this once Ruby 1.9.3 support is gone!
|
63
|
+
private static final int FIXNUM = 1;
|
64
|
+
private static final int BIGNUM = 2;
|
65
|
+
private static final int ARRAY = 3;
|
66
|
+
private static final int STRING = 4;
|
67
|
+
private static final int NIL = 5;
|
68
|
+
private static final int TRUE = 6;
|
69
|
+
private static final int FALSE = 7;
|
70
|
+
private static final int HASH = 10;
|
71
|
+
private static final int FLOAT = 11;
|
72
|
+
// hard-coded due JRuby 1.7 compatibility
|
73
|
+
// https://github.com/jruby/jruby/blob/1.7.27/core/src/main/java/org/jruby/runtime/ClassIndex.java
|
74
|
+
|
60
75
|
/**
|
61
76
|
* Returns the best serialization handler for the given object.
|
62
77
|
*/
|
@@ -65,16 +80,24 @@ public final class Generator {
|
|
65
80
|
@SuppressWarnings("unchecked")
|
66
81
|
private static <T extends IRubyObject>
|
67
82
|
Handler<? super T> getHandlerFor(Ruby runtime, T object) {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
83
|
+
switch (((RubyBasicObject) object).getNativeTypeIndex()) {
|
84
|
+
// can not use getNativeClassIndex due 1.7 compatibility
|
85
|
+
case NIL : return (Handler) NIL_HANDLER;
|
86
|
+
case TRUE : return (Handler) TRUE_HANDLER;
|
87
|
+
case FALSE : return (Handler) FALSE_HANDLER;
|
88
|
+
case FLOAT : return (Handler) FLOAT_HANDLER;
|
89
|
+
case FIXNUM : return (Handler) FIXNUM_HANDLER;
|
90
|
+
case BIGNUM : return (Handler) BIGNUM_HANDLER;
|
91
|
+
case STRING :
|
92
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getString()) break;
|
93
|
+
return (Handler) STRING_HANDLER;
|
94
|
+
case ARRAY :
|
95
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getArray()) break;
|
96
|
+
return (Handler) ARRAY_HANDLER;
|
97
|
+
case HASH :
|
98
|
+
if (((RubyBasicObject) object).getMetaClass() != runtime.getHash()) break;
|
99
|
+
return (Handler) HASH_HANDLER;
|
100
|
+
}
|
78
101
|
return GENERIC_HANDLER;
|
79
102
|
}
|
80
103
|
|
@@ -55,7 +55,7 @@ public class Parser extends RubyObject {
|
|
55
55
|
private RubyClass objectClass;
|
56
56
|
private RubyClass arrayClass;
|
57
57
|
private RubyClass decimalClass;
|
58
|
-
private RubyHash
|
58
|
+
private RubyHash match_string;
|
59
59
|
|
60
60
|
private static final int DEFAULT_MAX_NESTING = 100;
|
61
61
|
|
@@ -165,7 +165,7 @@ public class Parser extends RubyObject {
|
|
165
165
|
this.objectClass = opts.getClass("object_class", runtime.getHash());
|
166
166
|
this.arrayClass = opts.getClass("array_class", runtime.getArray());
|
167
167
|
this.decimalClass = opts.getClass("decimal_class", null);
|
168
|
-
this.
|
168
|
+
this.match_string = opts.getHash("match_string");
|
169
169
|
|
170
170
|
if(symbolizeNames && createAdditions) {
|
171
171
|
throw runtime.newArgumentError(
|
@@ -1437,7 +1437,7 @@ case 5:
|
|
1437
1437
|
// line 608 "Parser.rl"
|
1438
1438
|
|
1439
1439
|
if (parser.createAdditions) {
|
1440
|
-
RubyHash matchString = parser.
|
1440
|
+
RubyHash matchString = parser.match_string;
|
1441
1441
|
if (matchString != null) {
|
1442
1442
|
final IRubyObject[] memoArray = { result, null };
|
1443
1443
|
try {
|
data/java/src/json/ext/Parser.rl
CHANGED
@@ -607,7 +607,7 @@ public class Parser extends RubyObject {
|
|
607
607
|
%% write exec;
|
608
608
|
|
609
609
|
if (parser.createAdditions) {
|
610
|
-
RubyHash matchString = parser.
|
610
|
+
RubyHash matchString = parser.match_string;
|
611
611
|
if (matchString != null) {
|
612
612
|
final IRubyObject[] memoArray = { result, null };
|
613
613
|
try {
|
data/json-java.gemspec
CHANGED
@@ -8,9 +8,8 @@ spec = Gem::Specification.new do |s|
|
|
8
8
|
s.description = "A JSON implementation as a JRuby extension."
|
9
9
|
s.author = "Daniel Luz"
|
10
10
|
s.email = "dev+ruby@mernen.com"
|
11
|
-
s.homepage = "http://
|
11
|
+
s.homepage = "http://flori.github.com/json"
|
12
12
|
s.platform = 'java'
|
13
|
-
s.rubyforge_project = "json-jruby"
|
14
13
|
s.licenses = ["Ruby"]
|
15
14
|
|
16
15
|
s.files = Dir["{docs,lib,tests}/**/*"]
|
data/json.gemspec
CHANGED
Binary file
|
data/json_pure.gemspec
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: json_pure 2.
|
2
|
+
# stub: json_pure 2.3.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "json_pure".freeze
|
6
|
-
s.version = "2.
|
6
|
+
s.version = "2.3.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "
|
11
|
+
s.date = "2019-12-11"
|
12
12
|
s.description = "This is a JSON implementation in pure Ruby.".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze]
|
15
|
-
s.files = ["./tests/test_helper.rb".freeze, ".gitignore".freeze, ".travis.yml".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README-json-jruby.md".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "
|
15
|
+
s.files = ["./tests/test_helper.rb".freeze, ".gitignore".freeze, ".travis.yml".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README-json-jruby.md".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "diagrams/.keep".freeze, "ext/json/ext/fbuffer/fbuffer.h".freeze, "ext/json/ext/generator/depend".freeze, "ext/json/ext/generator/extconf.rb".freeze, "ext/json/ext/generator/generator.c".freeze, "ext/json/ext/generator/generator.h".freeze, "ext/json/ext/parser/depend".freeze, "ext/json/ext/parser/extconf.rb".freeze, "ext/json/ext/parser/parser.c".freeze, "ext/json/ext/parser/parser.h".freeze, "ext/json/ext/parser/parser.rl".freeze, "ext/json/extconf.rb".freeze, "install.rb".freeze, "java/src/json/ext/ByteListTranscoder.java".freeze, "java/src/json/ext/Generator.java".freeze, "java/src/json/ext/GeneratorMethods.java".freeze, "java/src/json/ext/GeneratorService.java".freeze, "java/src/json/ext/GeneratorState.java".freeze, "java/src/json/ext/OptionsReader.java".freeze, "java/src/json/ext/Parser.java".freeze, "java/src/json/ext/Parser.rl".freeze, "java/src/json/ext/ParserService.java".freeze, "java/src/json/ext/RuntimeInfo.java".freeze, "java/src/json/ext/StringDecoder.java".freeze, "java/src/json/ext/StringEncoder.java".freeze, "java/src/json/ext/Utils.java".freeze, "json-java.gemspec".freeze, "json.gemspec".freeze, "json_pure.gemspec".freeze, "lib/json.rb".freeze, "lib/json/add/bigdecimal.rb".freeze, "lib/json/add/complex.rb".freeze, "lib/json/add/core.rb".freeze, "lib/json/add/date.rb".freeze, "lib/json/add/date_time.rb".freeze, "lib/json/add/exception.rb".freeze, "lib/json/add/ostruct.rb".freeze, "lib/json/add/range.rb".freeze, "lib/json/add/rational.rb".freeze, "lib/json/add/regexp.rb".freeze, "lib/json/add/set.rb".freeze, "lib/json/add/struct.rb".freeze, "lib/json/add/symbol.rb".freeze, "lib/json/add/time.rb".freeze, "lib/json/common.rb".freeze, "lib/json/ext.rb".freeze, "lib/json/ext/.keep".freeze, "lib/json/generic_object.rb".freeze, "lib/json/pure.rb".freeze, "lib/json/pure/generator.rb".freeze, "lib/json/pure/parser.rb".freeze, "lib/json/version.rb".freeze, "references/rfc7159.txt".freeze, "tests/fixtures/fail10.json".freeze, "tests/fixtures/fail11.json".freeze, "tests/fixtures/fail12.json".freeze, "tests/fixtures/fail13.json".freeze, "tests/fixtures/fail14.json".freeze, "tests/fixtures/fail18.json".freeze, "tests/fixtures/fail19.json".freeze, "tests/fixtures/fail2.json".freeze, "tests/fixtures/fail20.json".freeze, "tests/fixtures/fail21.json".freeze, "tests/fixtures/fail22.json".freeze, "tests/fixtures/fail23.json".freeze, "tests/fixtures/fail24.json".freeze, "tests/fixtures/fail25.json".freeze, "tests/fixtures/fail27.json".freeze, "tests/fixtures/fail28.json".freeze, "tests/fixtures/fail3.json".freeze, "tests/fixtures/fail4.json".freeze, "tests/fixtures/fail5.json".freeze, "tests/fixtures/fail6.json".freeze, "tests/fixtures/fail7.json".freeze, "tests/fixtures/fail8.json".freeze, "tests/fixtures/fail9.json".freeze, "tests/fixtures/obsolete_fail1.json".freeze, "tests/fixtures/pass1.json".freeze, "tests/fixtures/pass15.json".freeze, "tests/fixtures/pass16.json".freeze, "tests/fixtures/pass17.json".freeze, "tests/fixtures/pass2.json".freeze, "tests/fixtures/pass26.json".freeze, "tests/fixtures/pass3.json".freeze, "tests/json_addition_test.rb".freeze, "tests/json_common_interface_test.rb".freeze, "tests/json_encoding_test.rb".freeze, "tests/json_ext_parser_test.rb".freeze, "tests/json_fixtures_test.rb".freeze, "tests/json_generator_test.rb".freeze, "tests/json_generic_object_test.rb".freeze, "tests/json_parser_test.rb".freeze, "tests/json_string_matching_test.rb".freeze, "tests/test_helper.rb".freeze, "tools/diff.sh".freeze, "tools/fuzz.rb".freeze, "tools/server.rb".freeze]
|
16
16
|
s.homepage = "http://flori.github.com/json".freeze
|
17
17
|
s.licenses = ["Ruby".freeze]
|
18
18
|
s.rdoc_options = ["--title".freeze, "JSON implemention for ruby".freeze, "--main".freeze, "README.md".freeze]
|
19
19
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9".freeze)
|
20
|
-
s.rubygems_version = "
|
20
|
+
s.rubygems_version = "3.0.3".freeze
|
21
21
|
s.summary = "JSON Implementation for Ruby".freeze
|
22
22
|
s.test_files = ["./tests/test_helper.rb".freeze]
|
23
23
|
|
data/lib/json/add/bigdecimal.rb
CHANGED
data/lib/json/add/complex.rb
CHANGED
data/lib/json/add/ostruct.rb
CHANGED
data/lib/json/add/rational.rb
CHANGED
data/lib/json/add/regexp.rb
CHANGED
data/lib/json/add/set.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
unless defined?(::JSON::JSON_LOADED) and ::JSON::JSON_LOADED
|
2
|
+
require 'json'
|
3
|
+
end
|
4
|
+
defined?(::Set) or require 'set'
|
5
|
+
|
6
|
+
class Set
|
7
|
+
# Import a JSON Marshalled object.
|
8
|
+
#
|
9
|
+
# method used for JSON marshalling support.
|
10
|
+
def self.json_create(object)
|
11
|
+
new object['a']
|
12
|
+
end
|
13
|
+
|
14
|
+
# Marshal the object to JSON.
|
15
|
+
#
|
16
|
+
# method used for JSON marshalling support.
|
17
|
+
def as_json(*)
|
18
|
+
{
|
19
|
+
JSON.create_id => self.class.name,
|
20
|
+
'a' => to_a,
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
# return the JSON value
|
25
|
+
def to_json(*args)
|
26
|
+
as_json.to_json(*args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/json/common.rb
CHANGED
@@ -153,7 +153,7 @@ module JSON
|
|
153
153
|
# * *object_class*: Defaults to Hash
|
154
154
|
# * *array_class*: Defaults to Array
|
155
155
|
def parse(source, opts = {})
|
156
|
-
Parser.new(source, opts).parse
|
156
|
+
Parser.new(source, **(opts||{})).parse
|
157
157
|
end
|
158
158
|
|
159
159
|
# Parse the JSON document _source_ into a Ruby data structure and return it.
|
@@ -176,7 +176,7 @@ module JSON
|
|
176
176
|
:max_nesting => false,
|
177
177
|
:allow_nan => true
|
178
178
|
}.merge(opts)
|
179
|
-
Parser.new(source, opts).parse
|
179
|
+
Parser.new(source, **(opts||{})).parse
|
180
180
|
end
|
181
181
|
|
182
182
|
# Generate a JSON document from the Ruby data structure _obj_ and return
|
data/lib/json/pure/generator.rb
CHANGED
data/lib/json/pure/parser.rb
CHANGED
@@ -197,7 +197,15 @@ module JSON
|
|
197
197
|
def parse_value
|
198
198
|
case
|
199
199
|
when scan(FLOAT)
|
200
|
-
|
200
|
+
if @decimal_class then
|
201
|
+
if @decimal_class == BigDecimal then
|
202
|
+
BigDecimal(self[1])
|
203
|
+
else
|
204
|
+
@decimal_class.new(self[1]) || Float(self[1])
|
205
|
+
end
|
206
|
+
else
|
207
|
+
Float(self[1])
|
208
|
+
end
|
201
209
|
when scan(INTEGER)
|
202
210
|
Integer(self[1])
|
203
211
|
when scan(TRUE)
|
data/lib/json/version.rb
CHANGED
data/tests/json_addition_test.rb
CHANGED
@@ -5,6 +5,7 @@ require 'json/add/complex'
|
|
5
5
|
require 'json/add/rational'
|
6
6
|
require 'json/add/bigdecimal'
|
7
7
|
require 'json/add/ostruct'
|
8
|
+
require 'json/add/set'
|
8
9
|
require 'date'
|
9
10
|
|
10
11
|
class JSONAdditionTest < Test::Unit::TestCase
|
@@ -190,4 +191,13 @@ class JSONAdditionTest < Test::Unit::TestCase
|
|
190
191
|
o.foo = { 'bar' => true }
|
191
192
|
assert_equal o, parse(JSON(o), :create_additions => true)
|
192
193
|
end
|
194
|
+
|
195
|
+
def test_set
|
196
|
+
s = Set.new([:a, :b, :c, :a])
|
197
|
+
assert_equal s, JSON.parse(JSON(s), :create_additions => true)
|
198
|
+
ss = SortedSet.new([:d, :b, :a, :c])
|
199
|
+
ss_again = JSON.parse(JSON(ss), :create_additions => true)
|
200
|
+
assert_kind_of ss.class, ss_again
|
201
|
+
assert_equal ss, ss_again
|
202
|
+
end
|
193
203
|
end
|
@@ -27,15 +27,15 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_parser
|
30
|
-
assert_match
|
30
|
+
assert_match(/::Parser\z/, JSON.parser.name)
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_generator
|
34
|
-
assert_match
|
34
|
+
assert_match(/::Generator\z/, JSON.generator.name)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_state
|
38
|
-
assert_match
|
38
|
+
assert_match(/::Generator::State\z/, JSON.state.name)
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_create_id
|
@@ -56,7 +56,7 @@ class JSONCommonInterfaceTest < Test::Unit::TestCase
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_parse_bang
|
59
|
-
assert_equal [ 1,
|
59
|
+
assert_equal [ 1, Infinity, 3, ], JSON.parse!('[ 1, Infinity, 3 ]')
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_generate
|