jrjackson 0.3.3 → 0.3.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ab793dfde79c3ac7811f5f24a59e9041dc8d49e
4
- data.tar.gz: e96d91f73dbedf976482f681157a45b2d5e8b740
3
+ metadata.gz: 549f6826999b9654a348daa2aaed4d80cdcd4014
4
+ data.tar.gz: ec6bc1ae63c834ee2a7c6ddfc6718f6b89897996
5
5
  SHA512:
6
- metadata.gz: 0acbeed9bb65e6b93ba3b0d3b9c2dea63ae9dcc39aaefc7b7505abb3484c9b432c110ee1f6a4f52bfd72f8bb1917485f10f9abe0a24ee892f056fede1f07b209
7
- data.tar.gz: 3f42fd81462bdc068f75fcae12484ad376a3f5d956c65c681da42e314017cac582cfc323ca9f48e286cf74b748ca823dba7356495bc8f861a319b5807f2fc80c
6
+ metadata.gz: 2a4c411e0caea3b5b83216382a7446a8eec67cfdded758b8b9b9377ce7b26d7ec6d09f262f39f6f5307acf5bbb5fcb0763e74bdffa7adc29c11405deea7bd0f4
7
+ data.tar.gz: 3ee2f6c6b9cb930db62214fb66efb495c6505fb209ae7232c509c544ff5fb97e2daa0c04af3e9840858e04d4a1b48260e8dce1f2991e06024e8f45f7623d062c
data/README.md CHANGED
@@ -12,18 +12,25 @@ __NOTE:__ Smile support has been temporarily dropped
12
12
 
13
13
  The code has been refactored to use almost all Java.
14
14
 
15
- There is now a MultiJson adapter added for JrJackson
15
+ There is now a MultiJson adapter added for JrJackson.
16
+
17
+ This release is compatible with JRuby 9.0.0.0 and higher.
16
18
 
17
19
  ***
18
20
 
19
21
  #### NEWS
20
22
 
23
+ 13th September 2015 - added support for a `to_json_data` method lookup.
24
+ Use this if you want to provide a JSON native data structure that best
25
+ represents your custom object.
26
+
21
27
  11th May 2014 - Added to_time method call for Ruby object serialization
22
28
 
23
29
  26th October 2013 - Added support to serialize arbitary (non JSON datatypes)
24
30
  ruby objects. Normally the toJava internal method is called, but additionally
25
31
  to_h, to_hash, to_a and finally to_json are tried. Be aware that the to_json
26
- method might invoke a new selialization session and impact performance.
32
+ method might invoke a new selialization session (i.e. it may use the JSON gem)
33
+ and impact performance.
27
34
 
28
35
  ***
29
36
 
@@ -43,7 +50,7 @@ The options hash respects three symbol keys
43
50
  + :raw
44
51
 
45
52
  Will return JRuby wrapped java objects that quack like ruby objects
46
- This is the fastest option
53
+ This is the fastest option but not by much
47
54
 
48
55
  + :use_bigdecimal
49
56
 
@@ -51,6 +58,10 @@ The options hash respects three symbol keys
51
58
  If used with the :raw option you will get Java::JavaMath::BigDecimal objects
52
59
  otherwise they are Ruby BigDecimal
53
60
 
61
+ + :use_smallint
62
+
63
+ Will return Integers objects instead of BigInteger
64
+
54
65
  ```
55
66
  JrJackson::Json.dump(obj) -> json string
56
67
  aliased as generate
@@ -64,12 +75,15 @@ serialization. See the wiki for more on this.
64
75
 
65
76
  #### Internals
66
77
 
67
- There are two Ruby sub modules of the JrJackson module
78
+ There are four Ruby sub modules of the JrJackson module
79
+
80
+ ```JrJackson::Json```, this is the general external facade used by MultiJson.
68
81
 
69
- ```JrJackson::Json```, this is the general external facade used by MultiJson, and is pure Ruby.
82
+ ```JrJackson::Raw```, this exists for backward compatibility, do not use this for new code.
70
83
 
71
- ```JrJackson::Raw```, this is used by the Json module, it is defined in Java with annotations
72
- exposing it as a Ruby module with module methods.
84
+ ```JrJackson::Ruby```, this is used by the external facade, you should use this directly. It returns Ruby objects e.g. Hash, Array, Symbol, String, Integer, BigDecimal etc.
85
+
86
+ ```JrJackson::Java```, this is used by the external facade, you should use this directly. It returns Java objects e.g. ArrayList, HashMap, BigDecimal, BigInteger, Long, Float and String, JRuby wraps (mostly) them in a JavaProxy Ruby object.
73
87
 
74
88
  ***
75
89
 
@@ -79,34 +93,55 @@ Credit to Chuck Remes for the benchmark and initial
79
93
  investigation when the jruby, json gem and the jackson
80
94
  libraries were young.
81
95
 
82
- 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
96
+ I compared Json (java) 1.8.3, Gson 0.6.1 and jackson 2.6.1 on jruby 1.7.22 and Oracle Java HotSpot(TM) 64-Bit Server VM 1.8.0_60-b27 +jit [linux-amd64]
83
97
  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.
84
98
 
85
99
  ```
86
100
  generation/serialize
87
101
 
88
102
  user system total real
89
- json mri generate: 250 12.02 0.00 12.02 ( 12.022)
90
- oj mri generate: 250 7.18 0.00 7.18 ( 7.183)
91
- json java generate: 250 7.83 0.01 7.84 ( 7.289)
92
- gson generate: 250 5.04 0.00 5.04 ( 4.995)
93
- jackson generate: 250 4.94 0.08 5.02 ( 4.811)
94
- jackson generate: 250 4.85 0.04 4.89 ( 4.758)
103
+
104
+
105
+ json java generate: 250 6.780 0.620 7.400 ( 6.599)
106
+ gson generate: 250 4.480 0.530 5.010 ( 4.688)
107
+ jackson generate: 250 2.200 0.010 2.210 ( 2.128)
108
+
109
+ json mri parse: 250 9.620 0.000 9.620 ( 9.631)
110
+ oj mri parse: 250 9.190 0.000 9.190 ( 9.199)
111
+ json mri generate: 250 8.400 0.010 8.410 ( 8.419)
112
+ oj mri generate: 250 6.980 0.010 6.990 ( 6.999)
95
113
 
96
114
 
97
115
  parsing/deserialize - after jrjackson parsing profiling
98
116
 
99
117
  user system total real
100
- json mri parse: 250 8.35 0.02 8.37 ( 8.366)
101
- oj mri parse: 250 6.10 0.13 6.23 ( 7.527)
102
-
103
- gson parse: 250 12.02 0.02 12.04 ( 11.774)
104
- json java parse: 250 10.35 0.01 10.36 ( 10.204)
105
- jackson parse string keys: 250 5.60 0.00 5.60 ( 5.356)
106
- jackson parse string + bigdecimal: 250 5.14 0.01 5.15 ( 4.946)
107
- jackson parse symbol keys: 250 4.16 0.01 4.17 ( 3.989)
108
- jackson parse symbol + bigdecimal: 250 3.90 0.03 3.93 ( 3.597)
109
- jackson parse raw: 250 3.08 0.01 3.09 ( 2.924)
110
- jackson parse raw + bigdecimal: 250 2.70 0.06 2.76 ( 2.493)
118
+ json java parse: 250 9.320 0.580 9.900 ( 9.467)
119
+ jackson parse string keys: 250 3.600 0.520 4.120 ( 3.823)
120
+ jackson parse string + bigdecimal: 250 3.390 0.640 4.030 ( 3.721)
121
+ jackson parse ruby compat: 250 3.700 0.030 3.730 ( 3.516)
122
+ jackson parse ruby ootb: 250 3.490 0.120 3.610 ( 3.420)
123
+ jackson parse sj: 250 3.290 0.030 3.320 ( 3.065)
124
+ jackson parse symbol keys: 250 3.050 0.120 3.170 ( 2.943)
125
+ jackson parse symbol + bigdecimal: 250 2.770 0.020 2.790 ( 2.669)
126
+ jackson parse java + bigdecimal: 250 1.880 0.430 2.310 ( 2.239)
127
+ jackson parse java + bigdecimal direct: 250 1.950 0.440 2.390 ( 2.290)
128
+ jackson parse java ootb: 250 1.990 0.030 2.020 ( 1.925)
129
+ jackson parse java sym bd: 250 1.920 0.000 1.920 ( 1.898)
130
+ ```
131
+
132
+ I have done IPS style benchmarks too.
133
+
134
+ Generation
135
+ ```
136
+ jrjackson: 74539.4 i/s
137
+ gson: 58288.3 i/s - 1.28x slower
138
+ JSON: 54597.2 i/s - 1.37x slower
139
+ ```
140
+
141
+ Parsing returning Ruby
142
+ ```
143
+ symbol keys
144
+ jrjackson: 95203.9 i/s
145
+ JSON: 40712.0 i/s - 2.34x slower
111
146
 
112
147
  ```
data/changelog.md CHANGED
@@ -1,3 +1,7 @@
1
+ v0.3.4
2
+ fix multi_json bug
3
+ not serializing non-string keys
4
+
1
5
  v0.3.3
2
6
  fix bigdecimal bug
3
7
  add require bigdecimal
@@ -1,11 +1,11 @@
1
1
  module JrJackson
2
2
  module BuildInfo
3
3
  def self.version
4
- '0.3.3'
4
+ '0.3.4'
5
5
  end
6
6
 
7
7
  def self.release_date
8
- '2015-09-12'
8
+ '2015-09-13'
9
9
  end
10
10
 
11
11
  def self.files
@@ -208,9 +208,12 @@ public class RubyAnySerializer {
208
208
 
209
209
  private void serializeKey(IRubyObject key, JsonGenerator jgen, SerializerProvider provider)
210
210
  throws IOException, JsonGenerationException {
211
-
212
- jgen.writeFieldName(key.asJavaString());
213
-
211
+ if(key instanceof RubyString) {
212
+ jgen.writeFieldName(((RubyString)key).decodeString());
213
+ } else {
214
+ // includes RubySymbol and non RubyString objects
215
+ jgen.writeFieldName(key.toString());
216
+ }
214
217
  }
215
218
 
216
219
  /**
@@ -6,9 +6,7 @@
6
6
  package com.jrjackson;
7
7
 
8
8
  import java.text.DateFormatSymbols;
9
- import java.text.FieldPosition;
10
9
  import java.text.SimpleDateFormat;
11
- import java.util.Date;
12
10
  import java.util.Locale;
13
11
 
14
12
  /**
@@ -477,6 +477,12 @@ class JrJacksonTest < Test::Unit::TestCase
477
477
  assert_equal "{\n \"foo\" : 5,\n \"utf8\" : \"żółć\"\n}", actual
478
478
  end
479
479
 
480
+ def test_can_serialise_non_string_keys
481
+ object = {5 => "foo"}
482
+ actual = JrJackson::Json.dump(object)
483
+ assert_equal "{\"5\":\"foo\"}", actual
484
+ end
485
+
480
486
  # -----------------------------
481
487
 
482
488
  def assert_bigdecimal_equal(expected, actual)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jrjackson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Boertje
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-12 00:00:00.000000000 Z
11
+ date: 2015-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement