jrjackson 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/changelog.md +4 -1
- data/lib/jrjackson/build_info.rb +2 -2
- data/lib/jrjackson/jars/jrjackson-1.2.16.jar +0 -0
- data/src/main/java/com/jrjackson/RubyAnySerializer.java +13 -13
- data/test/jrjackson_test.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81ef805539c250761b4457aea4fa82cfd23121e6
|
4
|
+
data.tar.gz: 8cfafab8e06ce0f3938e8d287d76f55064e55719
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cf160de8ff9750286c0c795399a68f98a667c6bcccb82c77b2c349dc1c22acaaaee66d4ac9fcc95cc246ee9d2f308480562a17b42c7978f0e085629e767b3dd
|
7
|
+
data.tar.gz: 52036310b4d62ca09766ffc99ee0464dfdee560051ad046fc01d282bc5e183ce02d4506966e428208918d96acc4d87438ad1b32269bcadefdaa03547865fbb08
|
data/README.md
CHANGED
@@ -20,6 +20,9 @@ This release is compatible with JRuby 9.0.0.0 and higher.
|
|
20
20
|
|
21
21
|
#### NEWS
|
22
22
|
|
23
|
+
07 October 2015 - during serialisation, check and execute `to_json_data` method
|
24
|
+
first.
|
25
|
+
|
23
26
|
13th September 2015 - added support for a `to_json_data` method lookup.
|
24
27
|
Use this if you want to provide a JSON native data structure that best
|
25
28
|
represents your custom object.
|
@@ -29,7 +32,7 @@ represents your custom object.
|
|
29
32
|
26th October 2013 - Added support to serialize arbitary (non JSON datatypes)
|
30
33
|
ruby objects. Normally the toJava internal method is called, but additionally
|
31
34
|
to_h, to_hash, to_a and finally to_json are tried. Be aware that the to_json
|
32
|
-
method might invoke a new selialization session (i.e. it may use the JSON gem)
|
35
|
+
method might invoke a new selialization session (i.e. it may use the JSON gem)
|
33
36
|
and impact performance.
|
34
37
|
|
35
38
|
***
|
@@ -61,7 +64,7 @@ The options hash respects three symbol keys
|
|
61
64
|
+ :use_smallint
|
62
65
|
|
63
66
|
Will return Integers objects instead of BigInteger
|
64
|
-
|
67
|
+
|
65
68
|
```
|
66
69
|
JrJackson::Json.dump(obj) -> json string
|
67
70
|
aliased as generate
|
data/changelog.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
v0.3.5
|
2
|
+
give highest precedence to the to_json_data method
|
3
|
+
|
1
4
|
v0.3.4
|
2
5
|
fix multi_json bug
|
3
6
|
not serializing non-string keys
|
@@ -90,7 +93,7 @@ v0.2.0
|
|
90
93
|
extract all Java -> Ruby generation to reusable RubyUtils static class
|
91
94
|
support BigDecimal
|
92
95
|
remove JSON Api
|
93
|
-
fixes issues 5, 6, 8,
|
96
|
+
fixes issues 5, 6, 8,
|
94
97
|
|
95
98
|
jruby 1.7.3
|
96
99
|
jackson 2.2.2
|
data/lib/jrjackson/build_info.rb
CHANGED
Binary file
|
@@ -43,8 +43,19 @@ public class RubyAnySerializer {
|
|
43
43
|
private void serializeUnknownRubyObject(ThreadContext ctx, IRubyObject rubyObject, JsonGenerator jgen, SerializerProvider provider)
|
44
44
|
throws IOException, JsonGenerationException {
|
45
45
|
RubyClass meta = rubyObject.getMetaClass();
|
46
|
-
|
47
|
-
DynamicMethod method = meta.searchMethod("
|
46
|
+
|
47
|
+
DynamicMethod method = meta.searchMethod("to_json_data");
|
48
|
+
if (!method.isUndefined()) {
|
49
|
+
RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_json_data");
|
50
|
+
if (obj instanceof RubyString) {
|
51
|
+
RubyUtils.writeBytes(obj, jgen);
|
52
|
+
} else {
|
53
|
+
serialize(obj, jgen, provider);
|
54
|
+
}
|
55
|
+
return;
|
56
|
+
}
|
57
|
+
|
58
|
+
method = meta.searchMethod("to_time");
|
48
59
|
if (!method.isUndefined()) {
|
49
60
|
RubyTime dt = (RubyTime) method.call(ctx, rubyObject, meta, "to_time");
|
50
61
|
serializeTime(dt, jgen, provider);
|
@@ -72,17 +83,6 @@ public class RubyAnySerializer {
|
|
72
83
|
return;
|
73
84
|
}
|
74
85
|
|
75
|
-
method = meta.searchMethod("to_json_data");
|
76
|
-
if (!method.isUndefined()) {
|
77
|
-
RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_json_data");
|
78
|
-
if (obj instanceof RubyString) {
|
79
|
-
RubyUtils.writeBytes(obj, jgen);
|
80
|
-
} else {
|
81
|
-
serialize(obj, jgen, provider);
|
82
|
-
}
|
83
|
-
return;
|
84
|
-
}
|
85
|
-
|
86
86
|
method = meta.searchMethod("to_json");
|
87
87
|
if (!method.isUndefined()) {
|
88
88
|
RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_json");
|
data/test/jrjackson_test.rb
CHANGED
@@ -22,6 +22,19 @@ class JrJacksonTest < Test::Unit::TestCase
|
|
22
22
|
# end
|
23
23
|
# end
|
24
24
|
|
25
|
+
class ToJsonData
|
26
|
+
attr_reader :one, :two, :six
|
27
|
+
def initialize(a,b,c)
|
28
|
+
@one, @two, @six = a,b,c
|
29
|
+
end
|
30
|
+
def to_h
|
31
|
+
{'one' => one, 'two' => two, 'six' => six}
|
32
|
+
end
|
33
|
+
def to_json_data
|
34
|
+
[one, two, six]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
25
38
|
class CustomToH
|
26
39
|
attr_accessor :one, :two, :six
|
27
40
|
def initialize(a,b,c)
|
@@ -207,6 +220,13 @@ class JrJacksonTest < Test::Unit::TestCase
|
|
207
220
|
)
|
208
221
|
end
|
209
222
|
|
223
|
+
def test_to_json_data
|
224
|
+
object = ToJsonData.new("uno", :two, 6.0)
|
225
|
+
expected = "[1,[\"uno\",\"two\",6.0]]"
|
226
|
+
actual = JrJackson::Json.dump([1, object])
|
227
|
+
assert_equal expected, actual
|
228
|
+
end
|
229
|
+
|
210
230
|
def test_datetime
|
211
231
|
h = {datetime: DateTime.parse("2014-01-27T18:24:46+01:00")}
|
212
232
|
expected = '{"datetime":"2014-01-27 17:24:46 +0000"}'
|
@@ -472,7 +492,7 @@ class JrJacksonTest < Test::Unit::TestCase
|
|
472
492
|
|
473
493
|
def test_supports_pretty_printing
|
474
494
|
object = {"foo" => 5, "utf8" => "żółć"}
|
475
|
-
|
495
|
+
|
476
496
|
actual = JrJackson::Json.dump(object, :pretty => true)
|
477
497
|
assert_equal "{\n \"foo\" : 5,\n \"utf8\" : \"żółć\"\n}", actual
|
478
498
|
end
|
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.
|
4
|
+
version: 0.3.5
|
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-
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|