jrjackson 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dependency-reduced-pom.xml +1 -1
- data/lib/jrjackson/build_info.rb +2 -2
- data/lib/jrjackson/jars/{jrjackson-1.2.16.jar → jrjackson-1.2.17.jar} +0 -0
- data/lib/jrjackson/jrjackson.rb +2 -2
- data/pom.xml +1 -1
- data/src/main/java/com/jrjackson/JrJacksonBase.java +0 -5
- data/src/main/java/com/jrjackson/RubyAnySerializer.java +6 -4
- data/src/main/java/com/jrjackson/RubyJacksonModule.java +8 -3
- data/test/jrjackson_test.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab68c0e2bee027c6cf4eb4559e909ccf4337d07b
|
4
|
+
data.tar.gz: 5af55667f2aeb5eeccc347e052cf6efa50f33ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a5509ef62f030a7f2d072926a9eecdfae1aa2bc69ba0df8154f3ad39b810e6ba1830ed0db54a205f251dc53b046f9b8fe5400e282aa3308cac78437e89d89b8
|
7
|
+
data.tar.gz: 90b940cf954d7dc2017cc83697d066fca867737ff75a023a28bd7d0459fa85e393cc225c288b9fc4311bffd7b4cdb916bc672d9e4b49feae29b01ffa6325e563
|
data/dependency-reduced-pom.xml
CHANGED
data/lib/jrjackson/build_info.rb
CHANGED
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.17.jar"
|
7
|
+
# require_relative "linked/jrjackson-1.2.17.jar"
|
8
8
|
|
9
9
|
require 'com/jrjackson/jr_jackson'
|
10
10
|
require 'bigdecimal'
|
data/pom.xml
CHANGED
@@ -47,10 +47,6 @@ public class JrJacksonBase extends RubyObject {
|
|
47
47
|
RubyHash options = (args.length <= 1) ? RubyHash.newHash(_ruby) : args[1].convertToHash();
|
48
48
|
String format = (String) options.get(RubyUtils.rubySymbol(_ruby, "date_format"));
|
49
49
|
|
50
|
-
// StringWriter out = new StringWriter();
|
51
|
-
// JsonGenerator jgen = RubyJacksonModule.factory.createGenerator(out);
|
52
|
-
|
53
|
-
|
54
50
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
55
51
|
JsonGenerator jgen = RubyJacksonModule.factory.createGenerator(
|
56
52
|
baos, JsonEncoding.UTF8);
|
@@ -78,7 +74,6 @@ public class JrJacksonBase extends RubyObject {
|
|
78
74
|
ByteList bl = new ByteList(baos.toByteArray(),
|
79
75
|
UTF8Encoding.INSTANCE);
|
80
76
|
return RubyString.newString(_ruby, bl);
|
81
|
-
// return RubyUtils.rubyString(_ruby, out.toString());
|
82
77
|
} catch (JsonProcessingException e) {
|
83
78
|
throw ParseError.newParseError(_ruby, e.getLocalizedMessage());
|
84
79
|
}
|
@@ -2,6 +2,7 @@ package com.jrjackson;
|
|
2
2
|
|
3
3
|
import com.fasterxml.jackson.core.JsonGenerationException;
|
4
4
|
import com.fasterxml.jackson.core.JsonGenerator;
|
5
|
+
import com.fasterxml.jackson.databind.JsonSerializer;
|
5
6
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
6
7
|
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
|
7
8
|
import org.jruby.ext.bigdecimal.RubyBigDecimal;
|
@@ -28,7 +29,7 @@ import org.jruby.RubyStruct;
|
|
28
29
|
import org.jruby.RubySymbol;
|
29
30
|
import org.jruby.RubyTime;
|
30
31
|
|
31
|
-
public class RubyAnySerializer {
|
32
|
+
public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
|
32
33
|
|
33
34
|
/**
|
34
35
|
* Singleton instance to use.""
|
@@ -43,7 +44,7 @@ public class RubyAnySerializer {
|
|
43
44
|
private void serializeUnknownRubyObject(ThreadContext ctx, IRubyObject rubyObject, JsonGenerator jgen, SerializerProvider provider)
|
44
45
|
throws IOException, JsonGenerationException {
|
45
46
|
RubyClass meta = rubyObject.getMetaClass();
|
46
|
-
|
47
|
+
|
47
48
|
DynamicMethod method = meta.searchMethod("to_json_data");
|
48
49
|
if (!method.isUndefined()) {
|
49
50
|
RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_json_data");
|
@@ -54,7 +55,7 @@ public class RubyAnySerializer {
|
|
54
55
|
}
|
55
56
|
return;
|
56
57
|
}
|
57
|
-
|
58
|
+
|
58
59
|
method = meta.searchMethod("to_time");
|
59
60
|
if (!method.isUndefined()) {
|
60
61
|
RubyTime dt = (RubyTime) method.call(ctx, rubyObject, meta, "to_time");
|
@@ -97,7 +98,7 @@ public class RubyAnySerializer {
|
|
97
98
|
throw new JsonGenerationException("Cannot find Serializer for class: " + rubyObject.getClass().getName());
|
98
99
|
}
|
99
100
|
|
100
|
-
|
101
|
+
@Override
|
101
102
|
public void serialize(IRubyObject value, JsonGenerator jgen, SerializerProvider provider)
|
102
103
|
throws IOException, JsonGenerationException {
|
103
104
|
|
@@ -226,6 +227,7 @@ public class RubyAnySerializer {
|
|
226
227
|
* @throws java.io.IOException
|
227
228
|
* @throws com.fasterxml.jackson.core.JsonGenerationException
|
228
229
|
*/
|
230
|
+
@Override
|
229
231
|
public void serializeWithType(IRubyObject value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer)
|
230
232
|
throws IOException, JsonGenerationException {
|
231
233
|
typeSer.writeTypePrefixForScalar(value, jgen);
|
@@ -11,6 +11,7 @@ import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
|
|
11
11
|
import java.text.SimpleDateFormat;
|
12
12
|
|
13
13
|
import org.jruby.Ruby;
|
14
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
14
15
|
|
15
16
|
public class RubyJacksonModule extends SimpleModule {
|
16
17
|
|
@@ -23,7 +24,7 @@ public class RubyJacksonModule extends SimpleModule {
|
|
23
24
|
}
|
24
25
|
|
25
26
|
private RubyJacksonModule() {
|
26
|
-
super("JrJacksonStrModule", new Version(1, 2,
|
27
|
+
super("JrJacksonStrModule", new Version(1, 2, 17, "0", "com.jrjackson.jruby", "jrjackson"));
|
27
28
|
}
|
28
29
|
|
29
30
|
public static ObjectMapper mapperWith(Ruby ruby, RubyKeyConverter nameConverter,
|
@@ -50,7 +51,12 @@ public class RubyJacksonModule extends SimpleModule {
|
|
50
51
|
}
|
51
52
|
|
52
53
|
public static DefaultSerializerProvider createProvider(SimpleDateFormat sdf) {
|
53
|
-
static_mapper.setDateFormat(sdf)
|
54
|
+
static_mapper.setDateFormat(sdf)
|
55
|
+
.registerModule(
|
56
|
+
new RubyJacksonModule().addSerializer(
|
57
|
+
IRubyObject.class, RubyAnySerializer.instance
|
58
|
+
)
|
59
|
+
);
|
54
60
|
return ((DefaultSerializerProvider)static_mapper.getSerializerProvider()).createInstance(
|
55
61
|
static_mapper.getSerializationConfig(),
|
56
62
|
static_mapper.getSerializerFactory()
|
@@ -63,5 +69,4 @@ public class RubyJacksonModule extends SimpleModule {
|
|
63
69
|
return static_mapper;
|
64
70
|
}
|
65
71
|
|
66
|
-
|
67
72
|
}
|
data/test/jrjackson_test.rb
CHANGED
@@ -511,6 +511,17 @@ class JrJacksonTest < Test::Unit::TestCase
|
|
511
511
|
assert_equal "{\"matched\":\"bar\"}", actual
|
512
512
|
end
|
513
513
|
|
514
|
+
def test_can_mix_java_and_ruby_objects
|
515
|
+
json = '{"utf8":"żółć", "moo": "bar", "arr": [2,3,4], "flo": 3.33}'
|
516
|
+
|
517
|
+
expected = '{"mixed":{"arr":[2,3,4],"utf8":"żółć","flo":3.33,"zzz":{"one":1.0,"two":2,"six":6.0},"moo":"bar"}}'
|
518
|
+
object = JrJackson::Json.parse_java(json)
|
519
|
+
object["zzz"] = CustomToJson.new(1.0, 2, 6.0)
|
520
|
+
mixed = {"mixed" => object}
|
521
|
+
actual = JrJackson::Json.dump(mixed)
|
522
|
+
assert_equal expected, actual
|
523
|
+
end
|
524
|
+
|
514
525
|
# -----------------------------
|
515
526
|
|
516
527
|
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.
|
4
|
+
version: 0.3.7
|
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-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ files:
|
|
42
42
|
- jrjackson.gemspec
|
43
43
|
- lib/jrjackson.rb
|
44
44
|
- lib/jrjackson/build_info.rb
|
45
|
-
- lib/jrjackson/jars/jrjackson-1.2.
|
45
|
+
- lib/jrjackson/jars/jrjackson-1.2.17.jar
|
46
46
|
- lib/jrjackson/jrjackson.rb
|
47
47
|
- lib/require_relative_patch.rb
|
48
48
|
- pom.xml
|