jrjackson 0.4.0-java → 0.4.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 982ae2aa319906690bf3f8f3fa6ecd40306cdeb5
4
- data.tar.gz: 3dfb8850a41321f74269587ae09b27a2a0253730
3
+ metadata.gz: 07684d7dc09c577c8ca59c40029b672740f54df5
4
+ data.tar.gz: 6b4ada75e21a4aa5db9cbda3c0a58ecc6d91f751
5
5
  SHA512:
6
- metadata.gz: a162733e1d223aa7da6b973d9bfbbbb8c5c5ec079720c4303a43611c21e3de0749f35fecddac6e514fce85b0b583cca25fb97f5a71c6cc0753235357c9fbd69b
7
- data.tar.gz: 5ca7749fd751a2edebd189e830c241cb51997c0a51fa9c844f0517578f0aa4c5fc96244912e0945e6710731e411547ab86ba509a47dfa24d70aeea1d7d4fef37
6
+ metadata.gz: 20fff6041d8ca57dad6828c43cc942948051d94ac76ce1958507170c556084d69b73ab5235a63d9367a795dd32bdf6f31ab7a46dbc05277c8457347dc979daaa
7
+ data.tar.gz: abc4caca39b0b37f302824d76ab230498d0cf25d4957dc5028145792493d494a08fcf4967a65a61b179e54f57e14fedd6cc379df173dd13c076a9d552da9d1ee
File without changes
data/Mavenfile CHANGED
@@ -1,6 +1,6 @@
1
1
  #-*- mode: ruby -*-
2
2
 
3
- VERSION='1.2.19'
3
+ VERSION='1.2.20'
4
4
  gemspec :jar => "jrjackson/jars/jrjackson-#{VERSION}.jar"
5
5
 
6
6
  # overwrite groupId:artifacgtId:version from gem
@@ -15,7 +15,7 @@ properties 'project.build.sourceEncoding' => 'UTF-8',
15
15
 
16
16
  jar 'junit:junit', '4.11', :scope => :test
17
17
 
18
- jar 'org.jruby:jruby', '9.0.5.0', :scope => :provided
18
+ jar 'org.jruby:jruby', '9.1.5.0', :scope => :provided
19
19
 
20
20
  plugin :compiler, '3.1', :source => '1.7', :target => '1.7',
21
21
  :showDeprecation => false,
data/changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ v0.4.1
2
+ fix for issue 55
3
+ Refactor AnySerializer acceptable class detection that does not use an exception
4
+
5
+ v0.4.0
6
+ Implement `to_s` and Exception serialization
7
+
1
8
  v0.3.9
2
9
  Thanks to mkristian, now uses jar_dependencies
3
10
  Upgrade to Jackson v2.7.1
@@ -1,11 +1,11 @@
1
1
  module JrJackson
2
2
  module BuildInfo
3
3
  def self.version
4
- '0.4.0'
4
+ '0.4.1'
5
5
  end
6
6
 
7
7
  def self.release_date
8
- '2016-05-11'
8
+ '2016-11-28'
9
9
  end
10
10
 
11
11
  def self.files
data/pom.xml CHANGED
@@ -11,7 +11,7 @@ DO NOT MODIFIY - GENERATED CODE
11
11
  <modelVersion>4.0.0</modelVersion>
12
12
  <groupId>com.jrjackson.jruby</groupId>
13
13
  <artifactId>jrjackson</artifactId>
14
- <version>1.2.19</version>
14
+ <version>1.2.20</version>
15
15
  <name>A JRuby wrapper for the java jackson json processor jar</name>
16
16
  <description>A mostly native JRuby wrapper for the java jackson json processor jar</description>
17
17
  <url>http://github.com/guyboertje/jrjackson</url>
@@ -88,7 +88,7 @@ DO NOT MODIFIY - GENERATED CODE
88
88
  <dependency>
89
89
  <groupId>org.jruby</groupId>
90
90
  <artifactId>jruby</artifactId>
91
- <version>9.0.5.0</version>
91
+ <version>9.1.5.0</version>
92
92
  <scope>provided</scope>
93
93
  </dependency>
94
94
  </dependencies>
@@ -126,7 +126,7 @@ DO NOT MODIFIY - GENERATED CODE
126
126
  </executions>
127
127
  <configuration>
128
128
  <outputDirectory>lib/jrjackson/jars</outputDirectory>
129
- <finalName>jrjackson-1.2.19</finalName>
129
+ <finalName>jrjackson-1.2.20</finalName>
130
130
  </configuration>
131
131
  </plugin>
132
132
  <plugin>
@@ -137,7 +137,7 @@ DO NOT MODIFIY - GENERATED CODE
137
137
  <fileset>
138
138
  <directory>lib/jrjackson/jars</directory>
139
139
  <includes>
140
- <include>jrjackson-1.2.19.jar</include>
140
+ <include>jrjackson-1.2.20.jar</include>
141
141
  <include>*/**/*.jar</include>
142
142
  </includes>
143
143
  </fileset>
@@ -12,25 +12,25 @@ import com.fasterxml.jackson.core.JsonParser;
12
12
  import com.fasterxml.jackson.core.JsonProcessingException;
13
13
  import com.fasterxml.jackson.databind.ObjectMapper;
14
14
  import com.fasterxml.jackson.databind.SerializerProvider;
15
- import java.io.ByteArrayOutputStream;
15
+ import org.jcodings.specific.UTF8Encoding;
16
+ import org.jruby.Ruby;
17
+ import org.jruby.RubyClass;
16
18
  import org.jruby.RubyHash;
17
19
  import org.jruby.RubyIO;
18
20
  import org.jruby.RubyObject;
19
21
  import org.jruby.RubyString;
22
+ import org.jruby.RubySymbol;
20
23
  import org.jruby.anno.JRubyMethod;
21
24
  import org.jruby.exceptions.RaiseException;
22
25
  import org.jruby.ext.stringio.StringIO;
23
26
  import org.jruby.runtime.ThreadContext;
24
27
  import org.jruby.runtime.builtin.IRubyObject;
28
+ import org.jruby.util.ByteList;
25
29
 
30
+ import java.io.ByteArrayOutputStream;
26
31
  import java.io.IOException;
27
32
  import java.text.SimpleDateFormat;
28
33
  import java.util.TimeZone;
29
- import org.jcodings.specific.UTF8Encoding;
30
- import org.jruby.Ruby;
31
- import org.jruby.RubyClass;
32
- import org.jruby.RubySymbol;
33
- import org.jruby.util.ByteList;
34
34
 
35
35
  /**
36
36
  *
@@ -27,6 +27,8 @@ public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
27
27
  private static final String CSP = ": ";
28
28
  private static final String GT = ">";
29
29
 
30
+ private static final RUBYCLASS[] CLASS_NAMES = RUBYCLASS.values();
31
+
30
32
  public RubyAnySerializer() {
31
33
  // super(IRubyObject.class);
32
34
 
@@ -104,78 +106,87 @@ public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
104
106
  String rubyClassName = value.getType().getName();
105
107
 
106
108
  if (value.isNil()) {
107
-
108
109
  jgen.writeNull(); // for RubyNil and NullObjects
110
+ return;
111
+ }
109
112
 
110
- } else if (value instanceof JavaProxy) {
111
-
113
+ if (value instanceof JavaProxy) {
112
114
  provider.defaultSerializeValue(((JavaProxy) value).getObject(), jgen);
115
+ return;
116
+ }
117
+
118
+ if (value instanceof RubyStruct) {
119
+ IRubyObject obj = value.callMethod(value.getRuntime().getCurrentContext(), "to_a");
120
+ serializeArray(obj, jgen, provider);
121
+ return;
122
+ }
113
123
 
114
- } else if (value instanceof RubyException) {
124
+ if (value instanceof RubyException) {
115
125
  RubyException re = (RubyException) value;
116
126
  String msg = re.message(value.getRuntime().getCurrentContext()).toString();
117
127
  StringBuilder sb = new StringBuilder(5 + rubyClassName.length() + msg.length());
118
128
  sb.append(HLT).append(rubyClassName).append(CSP).append(msg).append(GT);
119
129
  jgen.writeString(sb.toString());
130
+ return;
131
+ }
120
132
 
121
- } else if (value.isClass() || value.isModule()) {
122
-
133
+ if (value.isClass() || value.isModule()) {
123
134
  jgen.writeString(value.inspect().toString());
135
+ return;
136
+ }
124
137
 
125
- } else {
126
-
127
- RUBYCLASS clazz;
138
+ RUBYCLASS clazz = null;
128
139
 
129
- try {
130
- clazz = RUBYCLASS.valueOf(rubyClassName);
131
- } catch (IllegalArgumentException e) {
132
- serializeUnknownRubyObject(value.getRuntime().getCurrentContext(), value, jgen, provider);
133
- return;
140
+ for(RUBYCLASS v : CLASS_NAMES) {
141
+ if(rubyClassName.equals(v.name())) {
142
+ clazz = v;
143
+ break;
134
144
  }
145
+ }
135
146
 
136
- switch (clazz) {
137
- case Hash:
138
- serializeHash(value, jgen, provider);
139
- break;
140
- case Array:
141
- serializeArray(value, jgen, provider);
142
- break;
143
- case String:
144
- RubyUtils.writeBytes(value, jgen);
145
- break;
146
- case Symbol:
147
- case Date:
148
- // Date to_s -> yyyy-mm-dd
149
- RubyString s = value.asString();
150
- jgen.writeUTF8String(s.getBytes(), 0, s.size());
151
- break;
152
- case TrueClass:
153
- case FalseClass:
154
- jgen.writeBoolean(value.isTrue());
155
- break;
156
- case Float:
157
- jgen.writeNumber(RubyNumeric.num2dbl(value));
158
- break;
159
- case Fixnum:
160
- jgen.writeNumber(RubyNumeric.num2long(value));
161
- break;
162
- case Bignum:
163
- jgen.writeNumber(((RubyBignum) value).getBigIntegerValue());
164
- break;
165
- case BigDecimal:
166
- jgen.writeNumber(((RubyBigDecimal) value).getBigDecimalValue());
167
- break;
168
- case Struct:
169
- IRubyObject obj = value.callMethod(value.getRuntime().getCurrentContext(), "to_a");
170
- serializeArray(obj, jgen, provider);
171
- break;
172
- case Time:
173
- serializeTime((RubyTime) value, jgen, provider);
174
- break;
175
- default:
176
- serializeUnknownRubyObject(value.getRuntime().getCurrentContext(), value, jgen, provider);
177
- break;
178
- }
147
+ if (clazz == null) {
148
+ serializeUnknownRubyObject(value.getRuntime().getCurrentContext(), value, jgen, provider);
149
+ return;
150
+ }
151
+
152
+ switch (clazz) {
153
+ case Hash:
154
+ serializeHash(value, jgen, provider);
155
+ break;
156
+ case Array:
157
+ serializeArray(value, jgen, provider);
158
+ break;
159
+ case String:
160
+ RubyUtils.writeBytes(value, jgen);
161
+ break;
162
+ case Symbol:
163
+ case Date:
164
+ // Date to_s -> yyyy-mm-dd
165
+ RubyString s = value.asString();
166
+ jgen.writeUTF8String(s.getBytes(), 0, s.size());
167
+ break;
168
+ case TrueClass:
169
+ case FalseClass:
170
+ jgen.writeBoolean(value.isTrue());
171
+ break;
172
+ case Float:
173
+ jgen.writeNumber(RubyNumeric.num2dbl(value));
174
+ break;
175
+ case Fixnum:
176
+ jgen.writeNumber(RubyNumeric.num2long(value));
177
+ break;
178
+ case Bignum:
179
+ jgen.writeNumber(((RubyBignum) value).getBigIntegerValue());
180
+ break;
181
+ case BigDecimal:
182
+ jgen.writeNumber(((RubyBigDecimal) value).getBigDecimalValue());
183
+ break;
184
+ case Time:
185
+ serializeTime((RubyTime) value, jgen, provider);
186
+ break;
187
+ default:
188
+ serializeUnknownRubyObject(value.getRuntime().getCurrentContext(), value, jgen, provider);
189
+ break;
179
190
  }
180
191
  }
181
192
 
@@ -253,16 +264,15 @@ public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
253
264
 
254
265
  enum RUBYCLASS {
255
266
  String,
267
+ Fixnum,
268
+ Hash,
269
+ Array,
256
270
  Float,
257
271
  BigDecimal,
258
272
  Time,
259
- Array,
260
- Hash,
261
- Fixnum,
262
273
  Bignum,
263
274
  Date,
264
275
  Symbol,
265
- Struct,
266
276
  TrueClass,
267
277
  FalseClass
268
278
  }
@@ -0,0 +1,56 @@
1
+ package com.jrjackson;
2
+
3
+ import com.fasterxml.jackson.core.JsonEncoding;
4
+ import com.fasterxml.jackson.core.JsonGenerator;
5
+ import com.fasterxml.jackson.databind.SerializerProvider;
6
+ import org.jcodings.specific.UTF8Encoding;
7
+ import org.jruby.CompatVersion;
8
+ import org.jruby.Ruby;
9
+ import org.jruby.RubyHash;
10
+ import org.jruby.RubyInstanceConfig;
11
+ import org.jruby.ext.bigdecimal.RubyBigDecimal;
12
+ import org.jruby.util.ByteList;
13
+ import org.junit.Before;
14
+ import org.junit.Test;
15
+
16
+ import java.io.ByteArrayOutputStream;
17
+
18
+ import static org.hamcrest.CoreMatchers.equalTo;
19
+ import static org.hamcrest.CoreMatchers.is;
20
+ import static org.hamcrest.MatcherAssert.assertThat;
21
+
22
+ public class RubyAnySerializerTest {
23
+ private static boolean setupDone = false;
24
+ public static Ruby ruby;
25
+
26
+ @Before
27
+ public void setUp() throws Exception {
28
+ if (setupDone) return;
29
+
30
+ RubyInstanceConfig config_19 = new RubyInstanceConfig();
31
+ config_19.setCompatVersion(CompatVersion.RUBY1_9);
32
+ ruby = Ruby.newInstance(config_19);
33
+ RubyBigDecimal.createBigDecimal(ruby); // we need to do 'require "bigdecimal"'
34
+ // JrubyTimestampExtLibrary.createTimestamp(ruby);
35
+ setupDone = true;
36
+ }
37
+
38
+
39
+ @Test
40
+ public void testSerialize() throws Exception {
41
+ RubyHash rh = RubyHash.newHash(ruby);
42
+ rh.put("somekey", 123);
43
+
44
+ SerializerProvider provider = RubyJacksonModule.createProvider();
45
+
46
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
47
+ JsonGenerator jgen = RubyJacksonModule.factory.createGenerator(
48
+ baos, JsonEncoding.UTF8);
49
+
50
+ RubyAnySerializer.instance.serialize(rh, jgen, provider);
51
+ jgen.close();
52
+ ByteList bl = new ByteList(baos.toByteArray(),
53
+ UTF8Encoding.INSTANCE);
54
+ assertThat(bl.toString(), is(equalTo("{\"somekey\":123}")));
55
+ }
56
+ }
@@ -76,6 +76,9 @@ class JrJacksonTest < Test::Unit::TestCase
76
76
 
77
77
  CustomStruct = Struct.new(:one, :two, :six)
78
78
 
79
+ class StrangeError < RuntimeError
80
+
81
+ end
79
82
 
80
83
  class ScHandler
81
84
  attr_accessor :calls
@@ -522,9 +525,8 @@ class JrJacksonTest < Test::Unit::TestCase
522
525
  end
523
526
 
524
527
  def test_can_serialize_exceptions
525
- e = StandardError.new("Something immensely bad happened")
528
+ e = StrangeError.new("Something immensely bad happened")
526
529
  object = {'error' => e}
527
-
528
530
  actual = JrJackson::Json.dump(object)
529
531
  assert_equal "{\"error\":\"#{e.inspect}\"}", actual
530
532
  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.4.0
4
+ version: 0.4.1
5
5
  platform: java
6
6
  authors:
7
7
  - Guy Boertje
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-11 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -65,8 +65,8 @@ executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
- - .__jrubyrc
69
68
  - .gitignore
69
+ - .jrubyr_c
70
70
  - .mvn/extensions.xml
71
71
  - Gemfile
72
72
  - Mavenfile
@@ -81,7 +81,7 @@ files:
81
81
  - lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.7.3/jackson-module-afterburner-2.7.3.jar
82
82
  - lib/jrjackson.rb
83
83
  - lib/jrjackson/build_info.rb
84
- - lib/jrjackson/jars/jrjackson-1.2.19.jar
84
+ - lib/jrjackson/jars/jrjackson-1.2.20.jar
85
85
  - lib/jrjackson/jrjackson.rb
86
86
  - lib/jrjackson_jars.rb
87
87
  - lib/require_relative_patch.rb
@@ -128,6 +128,7 @@ files:
128
128
  - src/main/java/com/jrjackson/SajParse.java
129
129
  - src/main/java/com/jrjackson/SchParse.java
130
130
  - src/main/java/com/jrjackson/StreamParse.java
131
+ - src/test/java/com/jrjackson/RubyAnySerializerTest.java
131
132
  - test/jrjackson_test.rb
132
133
  homepage: http://github.com/guyboertje/jrjackson
133
134
  licenses: