jrjackson 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -19
- data/benchmarking/fixtures/bench_options.rb +4 -0
- data/benchmarking/individual/gson-gen-jr-sourced.rb +1 -1
- data/benchmarking/individual/gson-jr-sourced.rb +1 -1
- data/benchmarking/individual/json-gen-jr-sourced.rb +1 -1
- data/benchmarking/individual/json-gen-mri-sourced.rb +1 -1
- data/benchmarking/individual/json-jr-sourced.rb +1 -1
- data/benchmarking/individual/json-mri-sourced.rb +1 -1
- data/benchmarking/individual/oj-gen-mri-sourced.rb +1 -1
- data/benchmarking/individual/oj-mri-sourced.rb +1 -1
- data/benchmarking/individual/raw-bd-jr-sourced.rb +1 -1
- data/benchmarking/individual/raw-gen-jr-sourced.rb +1 -1
- data/benchmarking/individual/raw-jr-sourced.rb +1 -1
- data/benchmarking/individual/str-bd-jr-sourced.rb +1 -1
- data/benchmarking/individual/string-jr-sourced.rb +1 -1
- data/benchmarking/individual/sym-bd-jr-sourced.rb +1 -1
- data/benchmarking/individual/symbol-jr-sourced.rb +1 -1
- data/dependency-reduced-pom.xml +2 -2
- data/lib/jrjackson/jars/jrjackson-1.2.6.jar +0 -0
- data/lib/jrjackson/jrjackson.rb +3 -3
- data/lib/jrjackson/version.rb +1 -1
- data/pom.xml +2 -2
- data/run_all_individual_bench.sh +8 -8
- data/src/main/java/com/jrjackson/JrJacksonRaw.java +26 -49
- data/src/main/java/com/jrjackson/RubyJacksonModule.java +26 -22
- data/src/main/java/com/jrjackson/RubyKeyConverter.java +1 -1
- data/src/main/java/com/jrjackson/RubyObjectDeserializer.java +30 -28
- data/src/main/java/com/jrjackson/RubyStringConverter.java +2 -2
- data/src/main/java/com/jrjackson/RubySymbolConverter.java +2 -2
- data/test/jrjackson_test.rb +7 -0
- metadata +2 -2
- data/lib/jrjackson/jars/jrjackson-1.2.4.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbc02833dd5b438dabc8a6e6c3b0a42e9fcd4cca
|
4
|
+
data.tar.gz: 3d86d6411ee599ac5ea84c1d7ec0eadfb07b825a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6560285bd96536a57d0fcf723ef9ead449a1cc07514cf80cb12d6cfe4d475e042d8e5c66b9fd257348a94dc1cdcf4f47b886bc3fe76cd29cbae323910126733a
|
7
|
+
data.tar.gz: 4e6b988dd92ddf09181f4a3ff687be04eb2221fd71746c5859a9734e50cafba24fce6e9ffc200d0f0dc284f826f5851b577937c511d2a50d2079abdbdfab8e64
|
data/README.md
CHANGED
@@ -77,33 +77,34 @@ Credit to Chuck Remes for the benchmark and initial
|
|
77
77
|
investigation when the jruby, json gem and the jackson
|
78
78
|
libraries were young.
|
79
79
|
|
80
|
-
I compared Json (java) 1.8, Gson 0.6.1 and jackson 2.2.3 on jruby 1.7.
|
80
|
+
I compared Json (java) 1.8, Gson 0.6.1 and jackson 2.2.3 on jruby 1.7.5 and OpenJDK 64-Bit Server VM 1.7.0_25-b30
|
81
81
|
All the benchmarks were run separately. A 727.9KB string of random json data is read from a file and handled 250 times, thereby attempting to balance invocation and parsing benchmarking.
|
82
82
|
|
83
83
|
```
|
84
84
|
generation/serialize
|
85
85
|
|
86
|
-
|
87
|
-
json mri generate: 250
|
88
|
-
oj mri generate: 250
|
89
|
-
json java generate: 250
|
90
|
-
gson generate: 250
|
91
|
-
jackson generate: 250
|
86
|
+
user system total real
|
87
|
+
json mri generate: 250 12.02 0.00 12.02 ( 12.022)
|
88
|
+
oj mri generate: 250 7.18 0.00 7.18 ( 7.183)
|
89
|
+
json java generate: 250 7.83 0.01 7.84 ( 7.289)
|
90
|
+
gson generate: 250 5.04 0.00 5.04 ( 4.995)
|
91
|
+
jackson generate: 250 4.94 0.08 5.02 ( 4.811)
|
92
|
+
jackson generate: 250 4.85 0.04 4.89 ( 4.758)
|
92
93
|
|
93
94
|
|
94
95
|
parsing/deserialize - after jrjackson parsing profiling
|
95
96
|
|
96
|
-
|
97
|
-
json mri parse: 250
|
98
|
-
oj mri parse: 250
|
99
|
-
|
100
|
-
gson parse: 250
|
101
|
-
json java parse: 250
|
102
|
-
jackson parse string keys: 250
|
103
|
-
jackson parse string + bigdecimal: 250
|
104
|
-
jackson parse symbol keys: 250
|
105
|
-
jackson parse symbol + bigdecimal: 250
|
106
|
-
jackson parse raw: 250
|
107
|
-
jackson parse raw + bigdecimal: 250
|
97
|
+
user system total real
|
98
|
+
json mri parse: 250 8.35 0.02 8.37 ( 8.366)
|
99
|
+
oj mri parse: 250 6.10 0.13 6.23 ( 7.527)
|
100
|
+
|
101
|
+
gson parse: 250 12.02 0.02 12.04 ( 11.774)
|
102
|
+
json java parse: 250 10.35 0.01 10.36 ( 10.204)
|
103
|
+
jackson parse string keys: 250 5.60 0.00 5.60 ( 5.356)
|
104
|
+
jackson parse string + bigdecimal: 250 5.14 0.01 5.15 ( 4.946)
|
105
|
+
jackson parse symbol keys: 250 4.16 0.01 4.17 ( 3.989)
|
106
|
+
jackson parse symbol + bigdecimal: 250 3.90 0.03 3.93 ( 3.597)
|
107
|
+
jackson parse raw: 250 3.08 0.01 3.09 ( 2.924)
|
108
|
+
jackson parse raw + bigdecimal: 250 2.70 0.06 2.76 ( 2.493)
|
108
109
|
|
109
110
|
```
|
@@ -8,7 +8,7 @@ require File.expand_path('benchmarking/fixtures/bench_options')
|
|
8
8
|
filename = File.expand_path(BenchOptions.source)
|
9
9
|
hsh = JrJackson::Json.load(File.read(filename), use_bigdecimal: false, symbolize_keys: true)
|
10
10
|
|
11
|
-
Benchmark.bmbm(
|
11
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
12
12
|
x.report("gson generate: #{BenchOptions.iterations}") do
|
13
13
|
BenchOptions.iterations.times { ::Gson::Encoder.new({}).encode(hsh) }
|
14
14
|
end
|
@@ -7,7 +7,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
7
7
|
|
8
8
|
dumped_string = File.read(filename)
|
9
9
|
|
10
|
-
Benchmark.bmbm(
|
10
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
11
11
|
x.report("gson parse: #{BenchOptions.iterations}") do
|
12
12
|
BenchOptions.iterations.times { ::Gson::Decoder.new({}).decode(dumped_string) }
|
13
13
|
end
|
@@ -8,7 +8,7 @@ require File.expand_path('benchmarking/fixtures/bench_options')
|
|
8
8
|
filename = File.expand_path(BenchOptions.source)
|
9
9
|
hsh = JSON.parse(File.read(filename))
|
10
10
|
|
11
|
-
Benchmark.bmbm(
|
11
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
12
12
|
x.report("json java generate: #{BenchOptions.iterations}") do
|
13
13
|
BenchOptions.iterations.times { JSON.generate(hsh) }
|
14
14
|
end
|
@@ -9,7 +9,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
9
9
|
JSON.parser = JSON::Ext::Parser
|
10
10
|
hsh = JSON.parse(File.read(filename))
|
11
11
|
|
12
|
-
Benchmark.bmbm(
|
12
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
13
13
|
x.report("json mri generate: #{BenchOptions.iterations}") do
|
14
14
|
BenchOptions.iterations.times { JSON.fast_generate(hsh) }
|
15
15
|
end
|
@@ -7,7 +7,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
7
7
|
|
8
8
|
dumped_string = File.read(filename)
|
9
9
|
|
10
|
-
Benchmark.bmbm(
|
10
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
11
11
|
x.report("json java parse: #{BenchOptions.iterations}") do
|
12
12
|
BenchOptions.iterations.times { ::JSON.parse(dumped_string) }
|
13
13
|
end
|
@@ -8,7 +8,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
8
8
|
|
9
9
|
dumped_string = File.read(filename)
|
10
10
|
|
11
|
-
Benchmark.bmbm(
|
11
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
12
12
|
x.report("json mri parse: #{BenchOptions.iterations}") do
|
13
13
|
BenchOptions.iterations.times { JSON::Ext::Parser.new(dumped_string).parse }
|
14
14
|
end
|
@@ -6,7 +6,7 @@ require File.expand_path('benchmarking/fixtures/bench_options')
|
|
6
6
|
filename = File.expand_path(BenchOptions.source)
|
7
7
|
hsh = Oj.compat_load(File.read(filename))
|
8
8
|
|
9
|
-
Benchmark.bmbm(
|
9
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
10
10
|
x.report("oj mri generate: #{BenchOptions.iterations}") do
|
11
11
|
BenchOptions.iterations.times { Oj.dump(hsh) }
|
12
12
|
end
|
@@ -7,7 +7,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
7
7
|
|
8
8
|
dumped_string = File.read(filename)
|
9
9
|
|
10
|
-
Benchmark.bmbm(
|
10
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
11
11
|
x.report("oj mri parse: #{BenchOptions.iterations}") do
|
12
12
|
BenchOptions.iterations.times { Oj.compat_load(dumped_string) }
|
13
13
|
end
|
@@ -9,7 +9,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
9
9
|
opts = {use_bigdecimal: true, raw: true}
|
10
10
|
dumped_string = File.read(filename)
|
11
11
|
|
12
|
-
Benchmark.bmbm(
|
12
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
13
13
|
x.report("jackson parse raw + bigdecimal: #{BenchOptions.iterations}") do
|
14
14
|
BenchOptions.iterations.times { JrJackson::Json.load(dumped_string, opts) }
|
15
15
|
end
|
@@ -7,7 +7,7 @@ require File.expand_path('benchmarking/fixtures/bench_options')
|
|
7
7
|
filename = File.expand_path(BenchOptions.source)
|
8
8
|
hsh = JrJackson::Json.load(File.read(filename), use_bigdecimal: false, symbolize_keys: true)
|
9
9
|
|
10
|
-
Benchmark.bmbm(
|
10
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
11
11
|
x.report("jackson generate: #{BenchOptions.iterations}") do
|
12
12
|
BenchOptions.iterations.times { JrJackson::Raw.generate(hsh) }
|
13
13
|
end
|
@@ -9,7 +9,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
9
9
|
opts = {raw: true}
|
10
10
|
dumped_string = File.read(filename)
|
11
11
|
|
12
|
-
Benchmark.bmbm(
|
12
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
13
13
|
x.report("jackson parse raw: #{BenchOptions.iterations}") do
|
14
14
|
BenchOptions.iterations.times { JrJackson::Json.load(dumped_string, opts) }
|
15
15
|
end
|
@@ -9,7 +9,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
9
9
|
opts = {use_bigdecimal: true}
|
10
10
|
dumped_string = File.read(filename)
|
11
11
|
|
12
|
-
Benchmark.bmbm(
|
12
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
13
13
|
x.report("jackson parse string + bigdecimal: #{BenchOptions.iterations}") do
|
14
14
|
BenchOptions.iterations.times { JrJackson::Json.load(dumped_string, opts) }
|
15
15
|
end
|
@@ -9,7 +9,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
9
9
|
opts = nil
|
10
10
|
dumped_string = File.read(filename)
|
11
11
|
|
12
|
-
Benchmark.bmbm(
|
12
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
13
13
|
x.report("jackson parse string keys: #{BenchOptions.iterations}") do
|
14
14
|
BenchOptions.iterations.times { JrJackson::Json.load(dumped_string, opts) }
|
15
15
|
end
|
@@ -9,7 +9,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
9
9
|
opts = {use_bigdecimal: true, symbolize_keys: true}
|
10
10
|
dumped_string = File.read(filename)
|
11
11
|
|
12
|
-
Benchmark.bmbm(
|
12
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
13
13
|
x.report("jackson parse symbol + bigdecimal: #{BenchOptions.iterations}") do
|
14
14
|
BenchOptions.iterations.times { JrJackson::Json.load(dumped_string, opts) }
|
15
15
|
end
|
@@ -9,7 +9,7 @@ filename = File.expand_path(BenchOptions.source)
|
|
9
9
|
opts = {use_bigdecimal: false, symbolize_keys: true}
|
10
10
|
dumped_string = File.read(filename)
|
11
11
|
|
12
|
-
Benchmark.bmbm(
|
12
|
+
Benchmark.bmbm(BenchOptions.output_width) do |x|
|
13
13
|
x.report("jackson parse symbol keys: #{BenchOptions.iterations}") do
|
14
14
|
BenchOptions.iterations.times { JrJackson::Json.load(dumped_string, opts) }
|
15
15
|
end
|
data/dependency-reduced-pom.xml
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
<groupId>com.jrjackson.jruby</groupId>
|
5
5
|
<artifactId>jrjackson</artifactId>
|
6
6
|
<name>jrjackson</name>
|
7
|
-
<version>1.2.
|
7
|
+
<version>1.2.6</version>
|
8
8
|
<url>http://maven.apache.org</url>
|
9
9
|
<build>
|
10
10
|
<plugins>
|
@@ -65,7 +65,7 @@
|
|
65
65
|
<dependency>
|
66
66
|
<groupId>org.jruby</groupId>
|
67
67
|
<artifactId>jruby</artifactId>
|
68
|
-
<version>1.7.
|
68
|
+
<version>1.7.5</version>
|
69
69
|
<scope>compile</scope>
|
70
70
|
</dependency>
|
71
71
|
</dependencies>
|
Binary file
|
data/lib/jrjackson/jrjackson.rb
CHANGED
@@ -3,8 +3,8 @@ unless RUBY_PLATFORM =~ /java/
|
|
3
3
|
exit 255
|
4
4
|
end
|
5
5
|
|
6
|
-
require_relative "jars/jrjackson-1.2.
|
7
|
-
# require_relative "linked/jrjackson-1.2.
|
6
|
+
require_relative "jars/jrjackson-1.2.6.jar"
|
7
|
+
# require_relative "linked/jrjackson-1.2.6.jar"
|
8
8
|
|
9
9
|
require 'com/jrjackson/jr_jackson'
|
10
10
|
|
@@ -33,7 +33,7 @@ module JrJackson
|
|
33
33
|
|
34
34
|
def dump(object)
|
35
35
|
case object
|
36
|
-
when Array, Hash, String
|
36
|
+
when Array, Hash, String, Java::JavaUtil::LinkedHashMap
|
37
37
|
JrJackson::Raw.generate(object)
|
38
38
|
when true, false
|
39
39
|
object.to_s
|
data/lib/jrjackson/version.rb
CHANGED
data/pom.xml
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
<groupId>com.jrjackson.jruby</groupId>
|
6
6
|
<artifactId>jrjackson</artifactId>
|
7
7
|
<packaging>jar</packaging>
|
8
|
-
<version>1.2.
|
8
|
+
<version>1.2.6</version>
|
9
9
|
<name>jrjackson</name>
|
10
10
|
<url>http://maven.apache.org</url>
|
11
11
|
|
@@ -23,7 +23,7 @@
|
|
23
23
|
<dependency>
|
24
24
|
<groupId>org.jruby</groupId>
|
25
25
|
<artifactId>jruby</artifactId>
|
26
|
-
<version>1.7.
|
26
|
+
<version>1.7.5</version>
|
27
27
|
</dependency>
|
28
28
|
<dependency>
|
29
29
|
<groupId>com.fasterxml.jackson.core</groupId>
|
data/run_all_individual_bench.sh
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/bin/sh
|
2
2
|
|
3
|
-
ruby benchmarking/individual/json-mri-sourced.rb
|
4
|
-
ruby benchmarking/individual/oj-mri-sourced.rb
|
3
|
+
# ruby benchmarking/individual/json-mri-sourced.rb
|
4
|
+
# ruby benchmarking/individual/oj-mri-sourced.rb
|
5
5
|
|
6
|
-
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/gson-jr-sourced.rb
|
7
|
-
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/json-jr-sourced.rb
|
6
|
+
# jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/gson-jr-sourced.rb
|
7
|
+
# jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/json-jr-sourced.rb
|
8
8
|
|
9
9
|
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/string-jr-sourced.rb
|
10
10
|
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/str-bd-jr-sourced.rb
|
@@ -15,9 +15,9 @@ jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/sym-bd-jr-sourc
|
|
15
15
|
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/raw-jr-sourced.rb
|
16
16
|
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/raw-bd-jr-sourced.rb
|
17
17
|
|
18
|
-
ruby benchmarking/individual/json-gen-mri-sourced.rb
|
19
|
-
ruby benchmarking/individual/oj-gen-mri-sourced.rb
|
18
|
+
# ruby benchmarking/individual/json-gen-mri-sourced.rb
|
19
|
+
# ruby benchmarking/individual/oj-gen-mri-sourced.rb
|
20
20
|
|
21
|
-
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/json-gen-jr-sourced.rb
|
22
|
-
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/gson-gen-jr-sourced.rb
|
21
|
+
# jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/json-gen-jr-sourced.rb
|
22
|
+
# jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/gson-gen-jr-sourced.rb
|
23
23
|
jruby -J-Xmn512m -J-Xms2048m -J-Xmx2048m benchmarking/individual/raw-gen-jr-sourced.rb
|
@@ -25,38 +25,13 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
|
25
25
|
|
26
26
|
@JRubyModule(name = "JrJacksonRaw")
|
27
27
|
public class JrJacksonRaw extends RubyObject {
|
28
|
-
private static final HashMap<String, ObjectMapper> mappers = new HashMap<String, ObjectMapper>(3);
|
29
|
-
private static final HashMap<String, RubySymbol> symbols = new HashMap<String, RubySymbol>(3);
|
30
|
-
|
31
|
-
private static final Ruby _ruby = Ruby.getGlobalRuntime();
|
32
|
-
|
33
|
-
static {
|
34
|
-
mappers.put("str",
|
35
|
-
RubyJacksonModule.mappedAs("str")
|
36
|
-
);
|
37
|
-
mappers.put("sym",
|
38
|
-
RubyJacksonModule.mappedAs("sym")
|
39
|
-
);
|
40
|
-
mappers.put("raw",
|
41
|
-
RubyJacksonModule.mappedAs("raw")
|
42
|
-
);
|
43
|
-
symbols.put("sym",
|
44
|
-
RubyUtils.rubySymbol(_ruby, "symbolize_keys")
|
45
|
-
);
|
46
|
-
symbols.put("raw",
|
47
|
-
RubyUtils.rubySymbol(_ruby, "raw")
|
48
|
-
);
|
49
|
-
symbols.put("bigdecimal",
|
50
|
-
RubyUtils.rubySymbol(_ruby, "use_bigdecimal")
|
51
|
-
);
|
52
|
-
}
|
53
28
|
|
54
29
|
public JrJacksonRaw(Ruby ruby, RubyClass metaclass) {
|
55
30
|
super(ruby, metaclass);
|
56
31
|
}
|
57
32
|
|
58
|
-
private static boolean flagged(RubyHash opts,
|
59
|
-
Object val = opts.get(
|
33
|
+
private static boolean flagged(RubyHash opts, RubySymbol key) {
|
34
|
+
Object val = opts.get(key);
|
60
35
|
if (val == null) {
|
61
36
|
return false;
|
62
37
|
}
|
@@ -69,19 +44,21 @@ public class JrJacksonRaw extends RubyObject {
|
|
69
44
|
throws IOException
|
70
45
|
{
|
71
46
|
RubyHash options = null;
|
72
|
-
|
73
|
-
|
47
|
+
ObjectMapper local = null;
|
48
|
+
Ruby _ruby = context.getRuntime();
|
74
49
|
|
75
50
|
if (opts != context.nil) {
|
76
51
|
options = opts.convertToHash();
|
77
|
-
if (flagged(options, "
|
78
|
-
|
52
|
+
if (flagged(options, RubyUtils.rubySymbol(_ruby, "symbolize_keys"))) {
|
53
|
+
local = RubyJacksonModule.mappedAs("sym", _ruby);
|
79
54
|
}
|
80
|
-
if (flagged(options, "raw")) {
|
81
|
-
|
55
|
+
if (flagged(options, RubyUtils.rubySymbol(_ruby, "raw"))) {
|
56
|
+
local = RubyJacksonModule.mappedAs("raw", _ruby);
|
82
57
|
}
|
83
|
-
local
|
84
|
-
|
58
|
+
if (local == null) {
|
59
|
+
local = RubyJacksonModule.mappedAs("str", _ruby);
|
60
|
+
}
|
61
|
+
if (flagged(options, RubyUtils.rubySymbol(_ruby, "use_bigdecimal"))) {
|
85
62
|
local.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
|
86
63
|
}
|
87
64
|
else {
|
@@ -89,7 +66,7 @@ public class JrJacksonRaw extends RubyObject {
|
|
89
66
|
}
|
90
67
|
}
|
91
68
|
else {
|
92
|
-
local =
|
69
|
+
local = RubyJacksonModule.mappedAs("str", _ruby);
|
93
70
|
}
|
94
71
|
return _parse(context, arg, local);
|
95
72
|
}
|
@@ -98,28 +75,30 @@ public class JrJacksonRaw extends RubyObject {
|
|
98
75
|
public static IRubyObject parse_raw(ThreadContext context, IRubyObject self, IRubyObject arg)
|
99
76
|
throws IOException
|
100
77
|
{
|
101
|
-
|
78
|
+
ObjectMapper mapper = RubyJacksonModule.mappedAs("raw", context.getRuntime());
|
79
|
+
return _parse(context, arg, mapper);
|
102
80
|
}
|
103
81
|
|
104
82
|
@JRubyMethod(module = true, name = {"parse_sym", "load_sym"}, required = 1)
|
105
83
|
public static IRubyObject parse_sym(ThreadContext context, IRubyObject self, IRubyObject arg)
|
106
84
|
throws IOException
|
107
85
|
{
|
108
|
-
|
86
|
+
ObjectMapper mapper = RubyJacksonModule.mappedAs("sym", context.getRuntime());
|
87
|
+
return _parse(context, arg, mapper);
|
109
88
|
}
|
110
89
|
|
111
90
|
@JRubyMethod(module = true, name = {"parse_str", "load_str"}, required = 1)
|
112
91
|
public static IRubyObject parse_str(ThreadContext context, IRubyObject self, IRubyObject arg)
|
113
92
|
throws IOException
|
114
93
|
{
|
115
|
-
|
94
|
+
ObjectMapper mapper = RubyJacksonModule.mappedAs("str", context.getRuntime());
|
95
|
+
return _parse(context, arg, mapper);
|
116
96
|
}
|
117
97
|
|
118
|
-
|
98
|
+
private static IRubyObject _parse(ThreadContext context, IRubyObject arg, ObjectMapper mapper)
|
119
99
|
throws IOException
|
120
100
|
{
|
121
101
|
Ruby ruby = context.getRuntime();
|
122
|
-
|
123
102
|
try {
|
124
103
|
Object o;
|
125
104
|
if (arg instanceof RubyString) {
|
@@ -147,20 +126,18 @@ public class JrJacksonRaw extends RubyObject {
|
|
147
126
|
public static IRubyObject generate(ThreadContext context, IRubyObject self, IRubyObject arg)
|
148
127
|
throws IOException, JsonProcessingException
|
149
128
|
{
|
150
|
-
Ruby
|
129
|
+
Ruby _ruby = context.getRuntime();
|
151
130
|
Object obj = arg.toJava(Object.class);
|
152
|
-
// String s = mappers.get("raw").writeValueAsString(obj);
|
153
|
-
// return RubyUtils.rubyString(ruby, s);
|
154
|
-
|
155
131
|
try {
|
156
|
-
|
157
|
-
|
132
|
+
ObjectMapper mapper = RubyJacksonModule.mappedAs("raw", _ruby);
|
133
|
+
String s = mapper.writeValueAsString(obj);
|
134
|
+
return RubyUtils.rubyString(_ruby, s);
|
158
135
|
}
|
159
136
|
catch (JsonProcessingException e) {
|
160
|
-
throw ParseError.newParseError(
|
137
|
+
throw ParseError.newParseError(_ruby, e.getLocalizedMessage());
|
161
138
|
}
|
162
139
|
catch (IOException e) {
|
163
|
-
throw
|
140
|
+
throw _ruby.newIOError(e.getLocalizedMessage());
|
164
141
|
}
|
165
142
|
}
|
166
143
|
}
|
@@ -4,7 +4,6 @@ import java.util.*;
|
|
4
4
|
import java.text.SimpleDateFormat;
|
5
5
|
|
6
6
|
import org.jruby.*;
|
7
|
-
// import org.jruby.util.RubyDateFormat;
|
8
7
|
|
9
8
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
10
9
|
import com.fasterxml.jackson.databind.module.SimpleModule;
|
@@ -17,32 +16,39 @@ import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
|
|
17
16
|
public class RubyJacksonModule extends SimpleModule
|
18
17
|
{
|
19
18
|
|
19
|
+
private static final ObjectMapper static_mapper = new ObjectMapper().registerModule(
|
20
|
+
new RubyJacksonModule().addSerializer(RubyObject.class, RubyAnySerializer.instance)
|
21
|
+
);
|
22
|
+
|
23
|
+
static {
|
24
|
+
static_mapper.registerModule(new AfterburnerModule());
|
25
|
+
static_mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
26
|
+
static_mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"));
|
27
|
+
}
|
28
|
+
|
20
29
|
private RubyJacksonModule()
|
21
30
|
{
|
22
31
|
super("JrJacksonStrModule", VersionUtil.versionFor(RubyJacksonModule.class));
|
23
32
|
}
|
24
33
|
|
25
|
-
public static ObjectMapper mappedAs(String key)
|
34
|
+
public static ObjectMapper mappedAs(String key, Ruby ruby)
|
26
35
|
{
|
27
|
-
|
28
|
-
|
29
|
-
|
36
|
+
if (key == "raw") {
|
37
|
+
return static_mapper;
|
38
|
+
}
|
39
|
+
|
40
|
+
ObjectMapper mapper = new ObjectMapper().registerModule(
|
30
41
|
new AfterburnerModule()
|
31
42
|
);
|
32
43
|
|
33
44
|
if (key == "sym") {
|
34
45
|
mapper.registerModule(
|
35
|
-
asSym()
|
36
|
-
);
|
37
|
-
}
|
38
|
-
else if (key == "raw") {
|
39
|
-
mapper.registerModule(
|
40
|
-
asRaw()
|
46
|
+
asSym(ruby)
|
41
47
|
);
|
42
48
|
}
|
43
49
|
else {
|
44
50
|
mapper.registerModule(
|
45
|
-
asStr()
|
51
|
+
asStr(ruby)
|
46
52
|
);
|
47
53
|
}
|
48
54
|
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
@@ -50,28 +56,26 @@ public class RubyJacksonModule extends SimpleModule
|
|
50
56
|
return mapper;
|
51
57
|
}
|
52
58
|
|
53
|
-
public static SimpleModule asRaw()
|
54
|
-
{
|
55
|
-
|
56
|
-
|
57
|
-
);
|
58
|
-
}
|
59
|
+
// public static SimpleModule asRaw()
|
60
|
+
// {
|
61
|
+
// return static_mapper;
|
62
|
+
// }
|
59
63
|
|
60
|
-
public static SimpleModule asSym()
|
64
|
+
public static SimpleModule asSym(Ruby ruby)
|
61
65
|
{
|
62
66
|
return new RubyJacksonModule().addSerializer(
|
63
67
|
RubyObject.class, RubyAnySerializer.instance
|
64
68
|
).addDeserializer(
|
65
|
-
Object.class, new RubyObjectDeserializer().setSymbolStrategy()
|
69
|
+
Object.class, new RubyObjectDeserializer().withRuby(ruby).setSymbolStrategy()
|
66
70
|
);
|
67
71
|
}
|
68
72
|
|
69
|
-
public static SimpleModule asStr()
|
73
|
+
public static SimpleModule asStr(Ruby ruby)
|
70
74
|
{
|
71
75
|
return new RubyJacksonModule().addSerializer(
|
72
76
|
RubyObject.class, RubyAnySerializer.instance
|
73
77
|
).addDeserializer(
|
74
|
-
Object.class, new RubyObjectDeserializer().setStringStrategy()
|
78
|
+
Object.class, new RubyObjectDeserializer().withRuby(ruby).setStringStrategy()
|
75
79
|
);
|
76
80
|
}
|
77
81
|
}
|
@@ -22,16 +22,22 @@ public class RubyObjectDeserializer
|
|
22
22
|
{
|
23
23
|
private static final long serialVersionUID = 1L;
|
24
24
|
|
25
|
-
private final static RubyObject[] NO_OBJECTS = new RubyObject[0];
|
25
|
+
// private final static RubyObject[] NO_OBJECTS = new RubyObject[0];
|
26
26
|
|
27
|
-
|
27
|
+
private Ruby _ruby;
|
28
28
|
|
29
29
|
private RubyKeyConverter converter;
|
30
30
|
|
31
|
-
public RubyObjectDeserializer() {
|
31
|
+
public RubyObjectDeserializer() {
|
32
32
|
super(RubyObject.class);
|
33
33
|
}
|
34
34
|
|
35
|
+
public RubyObjectDeserializer withRuby(Ruby ruby)
|
36
|
+
{
|
37
|
+
_ruby = ruby;
|
38
|
+
return this;
|
39
|
+
}
|
40
|
+
|
35
41
|
public RubyObjectDeserializer setStringStrategy()
|
36
42
|
{
|
37
43
|
converter = new RubyStringConverter();
|
@@ -44,10 +50,6 @@ public class RubyObjectDeserializer
|
|
44
50
|
return this;
|
45
51
|
}
|
46
52
|
|
47
|
-
/**
|
48
|
-
* @since 2.2
|
49
|
-
*/
|
50
|
-
|
51
53
|
/**
|
52
54
|
/**********************************************************
|
53
55
|
/* Deserializer API
|
@@ -66,38 +68,38 @@ public class RubyObjectDeserializer
|
|
66
68
|
return mapArray(jp, ctxt);
|
67
69
|
|
68
70
|
case FIELD_NAME:
|
69
|
-
return converter.convert(jp);
|
71
|
+
return converter.convert(_ruby, jp);
|
70
72
|
|
71
73
|
case VALUE_EMBEDDED_OBJECT:
|
72
|
-
return RubyUtils.rubyObject(
|
74
|
+
return RubyUtils.rubyObject(_ruby, jp.getEmbeddedObject());
|
73
75
|
|
74
76
|
case VALUE_STRING:
|
75
|
-
// return RubyUtils.rubyString(
|
76
|
-
return RubyUtils.rubyString(
|
77
|
+
// return RubyUtils.rubyString(_ruby, jp.getText().getBytes("UTF-8"));
|
78
|
+
return RubyUtils.rubyString(_ruby, jp.getText());
|
77
79
|
|
78
80
|
case VALUE_NUMBER_INT:
|
79
81
|
/* [JACKSON-100]: caller may want to get all integral values
|
80
82
|
* returned as BigInteger, for consistency
|
81
83
|
*/
|
82
84
|
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)) {
|
83
|
-
return RubyUtils.rubyBignum(
|
85
|
+
return RubyUtils.rubyBignum(_ruby, jp.getBigIntegerValue());
|
84
86
|
}
|
85
|
-
return RubyUtils.rubyFixnum(
|
87
|
+
return RubyUtils.rubyFixnum(_ruby, jp.getLongValue());
|
86
88
|
|
87
89
|
case VALUE_NUMBER_FLOAT:
|
88
90
|
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
|
89
|
-
return RubyUtils.rubyBigDecimal(
|
91
|
+
return RubyUtils.rubyBigDecimal(_ruby, jp.getDecimalValue());
|
90
92
|
}
|
91
|
-
return RubyUtils.rubyFloat(
|
93
|
+
return RubyUtils.rubyFloat(_ruby, jp.getDoubleValue());
|
92
94
|
|
93
95
|
case VALUE_TRUE:
|
94
|
-
return
|
96
|
+
return _ruby.newBoolean(Boolean.TRUE);
|
95
97
|
|
96
98
|
case VALUE_FALSE:
|
97
|
-
return
|
99
|
+
return _ruby.newBoolean(Boolean.FALSE);
|
98
100
|
|
99
101
|
case VALUE_NULL: // should not get this but...
|
100
|
-
return
|
102
|
+
return (RubyObject)_ruby.getNil();
|
101
103
|
|
102
104
|
case END_ARRAY: // invalid
|
103
105
|
case END_OBJECT: // invalid
|
@@ -123,7 +125,7 @@ public class RubyObjectDeserializer
|
|
123
125
|
// }
|
124
126
|
// Minor optimization to handle small lists (default size for ArrayList is 10)
|
125
127
|
if (jp.nextToken() == JsonToken.END_ARRAY) {
|
126
|
-
return RubyArray.newArray(
|
128
|
+
return RubyArray.newArray(_ruby);
|
127
129
|
}
|
128
130
|
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
|
129
131
|
Object[] values = buffer.resetAndStart();
|
@@ -139,7 +141,7 @@ public class RubyObjectDeserializer
|
|
139
141
|
values[ptr++] = value;
|
140
142
|
} while (jp.nextToken() != JsonToken.END_ARRAY);
|
141
143
|
// let's create almost full array, with 1/8 slack
|
142
|
-
RubyArray result = RubyArray.newArray(
|
144
|
+
RubyArray result = RubyArray.newArray(_ruby, (totalSize + (totalSize >> 3) + 1));
|
143
145
|
buffer.completeAndClearBuffer(values, ptr, result);
|
144
146
|
return result;
|
145
147
|
}
|
@@ -157,29 +159,29 @@ public class RubyObjectDeserializer
|
|
157
159
|
// 1.6: minor optimization; let's handle 1 and 2 entry cases separately
|
158
160
|
if (t != JsonToken.FIELD_NAME) { // and empty one too
|
159
161
|
// empty map might work; but caller may want to modify... so better just give small modifiable
|
160
|
-
return RubyHash.newHash(
|
162
|
+
return RubyHash.newHash(_ruby);
|
161
163
|
}
|
162
164
|
|
163
|
-
RubyObject field1 = converter.convert(jp);
|
165
|
+
RubyObject field1 = converter.convert(_ruby, jp);
|
164
166
|
jp.nextToken();
|
165
167
|
RubyObject value1 = deserialize(jp, ctxt);
|
166
168
|
if (jp.nextToken() != JsonToken.FIELD_NAME) { // single entry; but we want modifiable
|
167
|
-
return RuntimeHelpers.constructHash(
|
169
|
+
return RuntimeHelpers.constructHash(_ruby, field1, value1);
|
168
170
|
}
|
169
171
|
|
170
|
-
RubyObject field2 = converter.convert(jp);
|
172
|
+
RubyObject field2 = converter.convert(_ruby, jp);
|
171
173
|
jp.nextToken();
|
172
174
|
RubyObject value2 = deserialize(jp, ctxt);
|
173
175
|
if (jp.nextToken() != JsonToken.FIELD_NAME) {
|
174
|
-
return RuntimeHelpers.constructHash(
|
176
|
+
return RuntimeHelpers.constructHash(_ruby, field1, value1, field2, value2);
|
175
177
|
}
|
176
178
|
|
177
179
|
// And then the general case; default map size is 16
|
178
|
-
RubyHash result = RuntimeHelpers.constructHash(
|
180
|
+
RubyHash result = RuntimeHelpers.constructHash(_ruby, field1, value1, field2, value2);
|
179
181
|
do {
|
180
|
-
RubyObject fieldName = converter.convert(jp);
|
182
|
+
RubyObject fieldName = converter.convert(_ruby, jp);
|
181
183
|
jp.nextToken();
|
182
|
-
result.fastASetCheckString(
|
184
|
+
result.fastASetCheckString(_ruby, fieldName, deserialize(jp, ctxt));
|
183
185
|
} while (jp.nextToken() != JsonToken.END_OBJECT);
|
184
186
|
return result;
|
185
187
|
}
|
@@ -8,7 +8,7 @@ import org.jruby.RubyObject;
|
|
8
8
|
|
9
9
|
public class RubyStringConverter implements RubyKeyConverter
|
10
10
|
{
|
11
|
-
public RubyObject convert(JsonParser jp) throws IOException {
|
12
|
-
return RubyUtils.rubyString(
|
11
|
+
public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
|
12
|
+
return RubyUtils.rubyString(ruby, jp.getText().getBytes());
|
13
13
|
}
|
14
14
|
}
|
@@ -8,7 +8,7 @@ import org.jruby.RubyObject;
|
|
8
8
|
|
9
9
|
public class RubySymbolConverter implements RubyKeyConverter
|
10
10
|
{
|
11
|
-
public RubyObject convert(JsonParser jp) throws IOException {
|
12
|
-
return RubyUtils.rubySymbol(
|
11
|
+
public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
|
12
|
+
return RubyUtils.rubySymbol(ruby, jp.getText());
|
13
13
|
}
|
14
14
|
}
|
data/test/jrjackson_test.rb
CHANGED
@@ -91,6 +91,13 @@ class JrJacksonTest < Test::Unit::TestCase
|
|
91
91
|
assert_equal expected, actual
|
92
92
|
end
|
93
93
|
|
94
|
+
def test_can_parse_nulls
|
95
|
+
expected = {"foo" => nil}
|
96
|
+
json = '{"foo":null}'
|
97
|
+
actual = JrJackson::Json.parse(json)
|
98
|
+
assert_equal expected, actual
|
99
|
+
end
|
100
|
+
|
94
101
|
def test_can_parse_big_decimals
|
95
102
|
expected = BigDecimal.new '0.12345678901234567890123456789'
|
96
103
|
json = '{"foo":0.12345678901234567890123456789}'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jrjackson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guy Boertje
|
@@ -59,7 +59,7 @@ files:
|
|
59
59
|
- dependency-reduced-pom.xml
|
60
60
|
- jrjackson.gemspec
|
61
61
|
- lib/jrjackson.rb
|
62
|
-
- lib/jrjackson/jars/jrjackson-1.2.
|
62
|
+
- lib/jrjackson/jars/jrjackson-1.2.6.jar
|
63
63
|
- lib/jrjackson/jrjackson.rb
|
64
64
|
- lib/jrjackson/version.rb
|
65
65
|
- lib/require_relative_patch.rb
|
Binary file
|