jrjackson 0.3.9-java → 0.4.0-java

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: d0880b3aefaaf4c13cbde88c6501ba2a297db4e9
4
- data.tar.gz: e168dcc7bf1990f23925263ff5d7893874e99e2d
3
+ metadata.gz: 982ae2aa319906690bf3f8f3fa6ecd40306cdeb5
4
+ data.tar.gz: 3dfb8850a41321f74269587ae09b27a2a0253730
5
5
  SHA512:
6
- metadata.gz: db9ea37b82fa3059c262e60d20b527d2de151b3394422142122901006ed30b25dd026ffb1898708ce5acda688d2b2ea8ee1454d65ecb4239e19e105fd264b4a1
7
- data.tar.gz: 1d932c32c8997bbf62b6325ba89530cfd10417434e17a330883f5574879758420e9570f13c3682df3f20884ed2f1513ad35761900fc25d27987e8d832d5753be
6
+ metadata.gz: a162733e1d223aa7da6b973d9bfbbbb8c5c5ec079720c4303a43611c21e3de0749f35fecddac6e514fce85b0b583cca25fb97f5a71c6cc0753235357c9fbd69b
7
+ data.tar.gz: 5ca7749fd751a2edebd189e830c241cb51997c0a51fa9c844f0517578f0aa4c5fc96244912e0945e6710731e411547ab86ba509a47dfa24d70aeea1d7d4fef37
data/Mavenfile CHANGED
@@ -1,6 +1,6 @@
1
1
  #-*- mode: ruby -*-
2
2
 
3
- VERSION='1.2.18'
3
+ VERSION='1.2.19'
4
4
  gemspec :jar => "jrjackson/jars/jrjackson-#{VERSION}.jar"
5
5
 
6
6
  # overwrite groupId:artifacgtId:version from gem
@@ -18,7 +18,7 @@ jar 'junit:junit', '4.11', :scope => :test
18
18
  jar 'org.jruby:jruby', '9.0.5.0', :scope => :provided
19
19
 
20
20
  plugin :compiler, '3.1', :source => '1.7', :target => '1.7',
21
- :showDeprecateion => false,
21
+ :showDeprecation => false,
22
22
  :showWarnings => false,
23
23
  :executable => '${JAVA_HOME}/bin/javac',
24
24
  :fork => true
data/jrjackson.gemspec CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.add_development_dependency 'jar-dependencies', '< 2.0', '>= 0.3.2'
22
22
  s.add_development_dependency 'ruby-maven', '~>3.3.10'
23
23
 
24
- JACKSON_VERSION = '2.7.1'
24
+ JACKSON_VERSION = '2.7.3'
25
25
  s.requirements << "jar com.fasterxml.jackson.core:jackson-core, #{JACKSON_VERSION}"
26
26
  s.requirements << "jar com.fasterxml.jackson.core:jackson-annotations, #{JACKSON_VERSION}"
27
27
  s.requirements << "jar com.fasterxml.jackson.core:jackson-databind, #{JACKSON_VERSION}"
@@ -1,11 +1,11 @@
1
1
  module JrJackson
2
2
  module BuildInfo
3
3
  def self.version
4
- '0.3.9'
4
+ '0.4.0'
5
5
  end
6
6
 
7
7
  def self.release_date
8
- '2016-04-09'
8
+ '2016-05-11'
9
9
  end
10
10
 
11
11
  def self.files
@@ -5,7 +5,7 @@ end
5
5
 
6
6
  require "jrjackson_jars"
7
7
 
8
- require_relative "jars/jrjackson-1.2.18.jar"
8
+ require_relative "jars/jrjackson-1.2.19.jar"
9
9
 
10
10
  require 'com/jrjackson/jr_jackson'
11
11
  require 'bigdecimal'
@@ -1,7 +1,16 @@
1
1
  # this is a generated file, to avoid over-writing it just delete this comment
2
- require 'jar_dependencies'
2
+ begin
3
+ require 'jar_dependencies'
4
+ rescue LoadError
5
+ require 'com/fasterxml/jackson/core/jackson-databind/2.7.3/jackson-databind-2.7.3.jar'
6
+ require 'com/fasterxml/jackson/core/jackson-annotations/2.7.3/jackson-annotations-2.7.3.jar'
7
+ require 'com/fasterxml/jackson/module/jackson-module-afterburner/2.7.3/jackson-module-afterburner-2.7.3.jar'
8
+ require 'com/fasterxml/jackson/core/jackson-core/2.7.3/jackson-core-2.7.3.jar'
9
+ end
3
10
 
4
- require_jar( 'com.fasterxml.jackson.core', 'jackson-core', '2.7.1' )
5
- require_jar( 'com.fasterxml.jackson.module', 'jackson-module-afterburner', '2.7.1' )
6
- require_jar( 'com.fasterxml.jackson.core', 'jackson-annotations', '2.7.1' )
7
- require_jar( 'com.fasterxml.jackson.core', 'jackson-databind', '2.7.1' )
11
+ if defined? Jars
12
+ require_jar( 'com.fasterxml.jackson.core', 'jackson-databind', '2.7.3' )
13
+ require_jar( 'com.fasterxml.jackson.core', 'jackson-annotations', '2.7.3' )
14
+ require_jar( 'com.fasterxml.jackson.module', 'jackson-module-afterburner', '2.7.3' )
15
+ require_jar( 'com.fasterxml.jackson.core', 'jackson-core', '2.7.3' )
16
+ end
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.18</version>
14
+ <version>1.2.19</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>
@@ -62,22 +62,22 @@ DO NOT MODIFIY - GENERATED CODE
62
62
  <dependency>
63
63
  <groupId>com.fasterxml.jackson.core</groupId>
64
64
  <artifactId>jackson-core</artifactId>
65
- <version>2.7.1</version>
65
+ <version>2.7.3</version>
66
66
  </dependency>
67
67
  <dependency>
68
68
  <groupId>com.fasterxml.jackson.core</groupId>
69
69
  <artifactId>jackson-annotations</artifactId>
70
- <version>2.7.1</version>
70
+ <version>2.7.3</version>
71
71
  </dependency>
72
72
  <dependency>
73
73
  <groupId>com.fasterxml.jackson.core</groupId>
74
74
  <artifactId>jackson-databind</artifactId>
75
- <version>2.7.1</version>
75
+ <version>2.7.3</version>
76
76
  </dependency>
77
77
  <dependency>
78
78
  <groupId>com.fasterxml.jackson.module</groupId>
79
79
  <artifactId>jackson-module-afterburner</artifactId>
80
- <version>2.7.1</version>
80
+ <version>2.7.3</version>
81
81
  </dependency>
82
82
  <dependency>
83
83
  <groupId>junit</groupId>
@@ -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.18</finalName>
129
+ <finalName>jrjackson-1.2.19</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.18.jar</include>
140
+ <include>jrjackson-1.2.19.jar</include>
141
141
  <include>*/**/*.jar</include>
142
142
  </includes>
143
143
  </fileset>
@@ -158,7 +158,7 @@ DO NOT MODIFIY - GENERATED CODE
158
158
  <configuration>
159
159
  <source>1.7</source>
160
160
  <target>1.7</target>
161
- <showDeprecateion>false</showDeprecateion>
161
+ <showDeprecation>false</showDeprecation>
162
162
  <showWarnings>false</showWarnings>
163
163
  <executable>${JAVA_HOME}/bin/javac</executable>
164
164
  <fork>true</fork>
@@ -1,42 +1,38 @@
1
1
  package com.jrjackson;
2
2
 
3
3
  import com.fasterxml.jackson.core.JsonParser;
4
- import com.fasterxml.jackson.core.JsonProcessingException;
5
4
  import com.fasterxml.jackson.core.JsonStreamContext;
5
+
6
6
  import java.io.IOException;
7
7
  import java.util.ArrayList;
8
8
  import java.util.HashMap;
9
9
 
10
-
11
10
  /**
12
11
  *
13
12
  * @author Guy Boertje
14
13
  */
15
14
  public class JjParse {
15
+
16
16
  private final JavaHandler _handler;
17
- protected final HashMap<JsonStreamContext, Object> _objectMap = new HashMap<JsonStreamContext, Object>();
18
- protected JsonStreamContext _deepestContext;
17
+ private final HashMap<JsonStreamContext, Object> _objectMap = new HashMap<>();
18
+ private JsonStreamContext _deepestContext;
19
19
 
20
20
  public JjParse(JavaHandler handler) {
21
21
  _handler = handler;
22
-
23
22
  }
24
23
 
25
- public void deserialize(JsonParser jp) throws JsonProcessingException, IOException {
24
+ public void deserialize(JsonParser jp) throws IOException {
26
25
  try {
27
26
 
28
27
  while (jp.nextValue() != null) {
29
- handleCurrentToken(jp);
28
+ handleJavaToken(jp);
30
29
  }
31
-
32
- } catch (JsonProcessingException e) {
33
- _handler.raiseError(e.getLocalizedMessage());
34
30
  } catch (IOException e) {
35
31
  _handler.raiseError(e.getLocalizedMessage());
36
32
  }
37
33
  }
38
34
 
39
- private void callAddValue(JsonStreamContext x) {
35
+ private void addJavaValue(JsonStreamContext x) {
40
36
  JsonStreamContext px = x.getParent();
41
37
  Object dtarget = _objectMap.get(_deepestContext);
42
38
 
@@ -52,28 +48,27 @@ public class JjParse {
52
48
  (ArrayList<Object>)value, dtarget);
53
49
  } else if (x.inObject()) {
54
50
  _handler.hashSet(
55
- (HashMap<String, Object>)value, callHashKey(x), dtarget);
51
+ (HashMap<String, Object>)value, getJavaHashKey(x), dtarget);
56
52
 
57
53
  } else {
58
54
  _handler.addValue(value);
59
55
  }
60
56
  }
61
57
 
62
- private void callAddValue(JsonStreamContext x, Object val) {
63
-
58
+ private void addJavaValue(JsonStreamContext x, Object val) {
64
59
  if (x.inArray()) {
65
60
  ArrayList<Object> a = (ArrayList<Object>)_objectMap.get(x);
66
61
  _handler.arrayAppend(a, val);
67
62
  } else if (x.inObject()) {
68
63
  HashMap<String, Object> h = (HashMap<String, Object>)_objectMap.get(x);
69
- _handler.hashSet(h, callHashKey(x), val);
64
+ _handler.hashSet(h, getJavaHashKey(x), val);
70
65
 
71
66
  } else {
72
67
  _handler.addValue(val);
73
68
  }
74
69
  }
75
70
 
76
- private String callHashKey(JsonStreamContext x) {
71
+ private String getJavaHashKey(JsonStreamContext x) {
77
72
  String k = x.getCurrentName();
78
73
  if (k == null) {
79
74
  return null;
@@ -81,8 +76,8 @@ public class JjParse {
81
76
  return (String)_handler.hashKey(k);
82
77
  }
83
78
 
84
- private void handleCurrentToken(JsonParser jp)
85
- throws IOException, JsonProcessingException {
79
+ protected void handleJavaToken(JsonParser jp)
80
+ throws IOException {
86
81
 
87
82
  JsonStreamContext cx = jp.getParsingContext();
88
83
 
@@ -105,41 +100,38 @@ public class JjParse {
105
100
  break;
106
101
 
107
102
  case VALUE_STRING:
108
- callAddValue(cx,
109
- _handler.treatString(jp));
103
+ addJavaValue(cx, _handler.treatString(jp));
110
104
  break;
111
105
 
112
106
  case VALUE_NUMBER_INT:
113
- callAddValue(cx,
114
- _handler.treatInt(jp));
107
+ addJavaValue(cx, _handler.treatInt(jp));
115
108
  break;
116
109
 
117
110
  case VALUE_NUMBER_FLOAT:
118
- callAddValue(cx,
119
- _handler.treatFloat(jp));
111
+ addJavaValue(cx, _handler.treatFloat(jp));
120
112
  break;
121
113
 
122
114
  case VALUE_TRUE:
123
- callAddValue(cx, _handler.trueValue());
115
+ addJavaValue(cx, _handler.trueValue());
124
116
  break;
125
117
 
126
118
  case VALUE_FALSE:
127
- callAddValue(cx, _handler.falseValue());
119
+ addJavaValue(cx, _handler.falseValue());
128
120
  break;
129
121
 
130
122
  case VALUE_NULL: // should not get this but...
131
- callAddValue(cx, _handler.treatNull());
123
+ addJavaValue(cx, _handler.treatNull());
132
124
  break;
133
125
 
134
126
  case END_ARRAY:
135
127
  _handler.arrayEnd();
136
- callAddValue(cx);
128
+ addJavaValue(cx);
137
129
  _deepestContext = cx;
138
130
  break;
139
131
 
140
132
  case END_OBJECT:
141
133
  _handler.hashEnd();
142
- callAddValue(cx);
134
+ addJavaValue(cx);
143
135
  _deepestContext = cx;
144
136
  break;
145
137
  }
@@ -1,14 +1,14 @@
1
1
  package com.jrjackson;
2
2
 
3
3
  import com.fasterxml.jackson.core.JsonParser;
4
- import com.fasterxml.jackson.core.JsonProcessingException;
5
4
  import com.fasterxml.jackson.core.JsonStreamContext;
6
- import java.io.IOException;
7
- import java.util.HashMap;
8
5
  import org.jruby.RubyArray;
9
6
  import org.jruby.RubyHash;
10
7
  import org.jruby.runtime.builtin.IRubyObject;
11
8
 
9
+ import java.io.IOException;
10
+ import java.util.HashMap;
11
+
12
12
 
13
13
  /**
14
14
  *
@@ -16,29 +16,25 @@ import org.jruby.runtime.builtin.IRubyObject;
16
16
  */
17
17
  public class JrParse {
18
18
  private final RubyHandler _handler;
19
- protected final HashMap<JsonStreamContext, IRubyObject> _objectMap = new HashMap<JsonStreamContext, IRubyObject>();
20
- protected JsonStreamContext _deepestContext;
19
+ private final HashMap<JsonStreamContext, IRubyObject> _objectMap = new HashMap<JsonStreamContext, IRubyObject>();
20
+ private JsonStreamContext _deepestContext;
21
21
 
22
22
  public JrParse(RubyHandler handler) {
23
23
  _handler = handler;
24
-
25
24
  }
26
-
27
- public void deserialize(JsonParser jp) throws JsonProcessingException, IOException {
25
+
26
+ public void deserialize(JsonParser jp) throws IOException {
28
27
  try {
29
-
28
+
30
29
  while (jp.nextValue() != null) {
31
- handleCurrentToken(jp);
30
+ handleRubyToken(jp);
32
31
  }
33
-
34
- } catch (JsonProcessingException e) {
35
- _handler.raiseError(e.getLocalizedMessage());
36
32
  } catch (IOException e) {
37
33
  _handler.raiseError(e.getLocalizedMessage());
38
34
  }
39
35
  }
40
-
41
- private void callAddValue(JsonStreamContext x) {
36
+
37
+ private void addRubyValue(JsonStreamContext x) {
42
38
  JsonStreamContext px = x.getParent();
43
39
  IRubyObject dtarget = _objectMap.get(_deepestContext);
44
40
 
@@ -54,28 +50,28 @@ public class JrParse {
54
50
  (RubyArray)value, dtarget);
55
51
  } else if (x.inObject()) {
56
52
  _handler.hashSet(
57
- (RubyHash)value, callHashKey(x), dtarget);
53
+ (RubyHash)value, getRubyHashKey(x), dtarget);
58
54
 
59
55
  } else {
60
56
  _handler.addValue(value);
61
57
  }
62
58
  }
63
59
 
64
- private void callAddValue(JsonStreamContext x, IRubyObject val) {
60
+ private void addRubyValue(JsonStreamContext x, IRubyObject val) {
65
61
 
66
62
  if (x.inArray()) {
67
63
  RubyArray a = (RubyArray)_objectMap.get(x);
68
64
  _handler.arrayAppend(a, val);
69
65
  } else if (x.inObject()) {
70
66
  RubyHash h = (RubyHash)_objectMap.get(x);
71
- _handler.hashSet(h, callHashKey(x), val);
67
+ _handler.hashSet(h, getRubyHashKey(x), val);
72
68
 
73
69
  } else {
74
70
  _handler.addValue(val);
75
71
  }
76
72
  }
77
73
 
78
- private IRubyObject callHashKey(JsonStreamContext x) {
74
+ private IRubyObject getRubyHashKey(JsonStreamContext x) {
79
75
  String k = x.getCurrentName();
80
76
  if (k == null) {
81
77
  return _handler.treatNull();
@@ -83,8 +79,8 @@ public class JrParse {
83
79
  return _handler.hashKey(k);
84
80
  }
85
81
 
86
- private void handleCurrentToken(JsonParser jp)
87
- throws IOException, JsonProcessingException {
82
+ protected void handleRubyToken(JsonParser jp)
83
+ throws IOException {
88
84
 
89
85
  JsonStreamContext cx = jp.getParsingContext();
90
86
 
@@ -107,41 +103,38 @@ public class JrParse {
107
103
  break;
108
104
 
109
105
  case VALUE_STRING:
110
- callAddValue(cx,
111
- _handler.treatString(jp));
106
+ addRubyValue(cx, _handler.treatString(jp));
112
107
  break;
113
108
 
114
109
  case VALUE_NUMBER_INT:
115
- callAddValue(cx,
116
- _handler.treatInt(jp));
110
+ addRubyValue(cx, _handler.treatInt(jp));
117
111
  break;
118
112
 
119
113
  case VALUE_NUMBER_FLOAT:
120
- callAddValue(cx,
121
- _handler.treatFloat(jp));
114
+ addRubyValue(cx, _handler.treatFloat(jp));
122
115
  break;
123
116
 
124
117
  case VALUE_TRUE:
125
- callAddValue(cx, _handler.trueValue());
118
+ addRubyValue(cx, _handler.trueValue());
126
119
  break;
127
120
 
128
121
  case VALUE_FALSE:
129
- callAddValue(cx, _handler.falseValue());
122
+ addRubyValue(cx, _handler.falseValue());
130
123
  break;
131
124
 
132
125
  case VALUE_NULL: // should not get this but...
133
- callAddValue(cx, _handler.treatNull());
126
+ addRubyValue(cx, _handler.treatNull());
134
127
  break;
135
128
 
136
129
  case END_ARRAY:
137
130
  _handler.arrayEnd();
138
- callAddValue(cx);
131
+ addRubyValue(cx);
139
132
  _deepestContext = cx;
140
133
  break;
141
134
 
142
135
  case END_OBJECT:
143
136
  _handler.hashEnd();
144
- callAddValue(cx);
137
+ addRubyValue(cx);
145
138
  _deepestContext = cx;
146
139
  break;
147
140
  }
@@ -5,8 +5,8 @@ import com.fasterxml.jackson.core.JsonGenerator;
5
5
  import com.fasterxml.jackson.databind.JsonSerializer;
6
6
  import com.fasterxml.jackson.databind.SerializerProvider;
7
7
  import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
8
+ import org.jruby.*;
8
9
  import org.jruby.ext.bigdecimal.RubyBigDecimal;
9
-
10
10
  import org.jruby.internal.runtime.methods.DynamicMethod;
11
11
  import org.jruby.java.proxies.JavaProxy;
12
12
  import org.jruby.runtime.ThreadContext;
@@ -15,39 +15,17 @@ import org.jruby.runtime.builtin.IRubyObject;
15
15
  import java.io.IOException;
16
16
  import java.text.DateFormat;
17
17
  import java.text.SimpleDateFormat;
18
- import org.jruby.RubyArray;
19
- import org.jruby.RubyBignum;
20
- import org.jruby.RubyClass;
21
- import org.jruby.RubyHash;
22
- import org.jruby.RubyNumeric;
23
- import org.jruby.RubyObject;
24
- import org.jruby.RubyString;
25
- import org.jruby.RubyTime;
26
18
 
27
19
 
28
20
  public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
29
21
 
30
- enum RUBYCLASS {
31
-
32
- String,
33
- Float,
34
- BigDecimal,
35
- Time,
36
- Array,
37
- Hash,
38
- Fixnum,
39
- Bignum,
40
- Date,
41
- Symbol,
42
- Struct,
43
- TrueClass,
44
- FalseClass;
45
- }
46
-
47
22
  /**
48
23
  * Singleton instance to use.""
49
24
  */
50
25
  public static final RubyAnySerializer instance = new RubyAnySerializer();
26
+ private static final String HLT = "#<";
27
+ private static final String CSP = ": ";
28
+ private static final String GT = ">";
51
29
 
52
30
  public RubyAnySerializer() {
53
31
  // super(IRubyObject.class);
@@ -107,13 +85,24 @@ public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
107
85
  }
108
86
  return;
109
87
  }
110
- throw new JsonGenerationException("Cannot serialize instance of: " + meta.getRealClass().getName(), jgen);
88
+
89
+ if (!RubyUtils.isBasicObjectOrSubclass(rubyObject) && rubyObject.respondsTo("to_s")) {
90
+ String result = rubyObject.toString();
91
+ jgen.writeString(result);
92
+ } else {
93
+ String name = meta.getRealClass().getName();
94
+ StringBuilder sb = new StringBuilder(2 + name.length());
95
+ sb.append(HLT).append(name).append(GT);
96
+ jgen.writeString(sb.toString());
97
+ }
111
98
  }
112
99
 
113
100
  @Override
114
101
  public void serialize(IRubyObject value, JsonGenerator jgen, SerializerProvider provider)
115
102
  throws IOException, JsonGenerationException {
116
103
 
104
+ String rubyClassName = value.getType().getName();
105
+
117
106
  if (value.isNil()) {
118
107
 
119
108
  jgen.writeNull(); // for RubyNil and NullObjects
@@ -122,9 +111,19 @@ public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
122
111
 
123
112
  provider.defaultSerializeValue(((JavaProxy) value).getObject(), jgen);
124
113
 
114
+ } else if (value instanceof RubyException) {
115
+ RubyException re = (RubyException) value;
116
+ String msg = re.message(value.getRuntime().getCurrentContext()).toString();
117
+ StringBuilder sb = new StringBuilder(5 + rubyClassName.length() + msg.length());
118
+ sb.append(HLT).append(rubyClassName).append(CSP).append(msg).append(GT);
119
+ jgen.writeString(sb.toString());
120
+
121
+ } else if (value.isClass() || value.isModule()) {
122
+
123
+ jgen.writeString(value.inspect().toString());
124
+
125
125
  } else {
126
126
 
127
- String rubyClassName = value.getMetaClass().getRealClass().getName();
128
127
  RUBYCLASS clazz;
129
128
 
130
129
  try {
@@ -251,4 +250,20 @@ public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
251
250
  serialize(value, jgen, provider);
252
251
  typeSer.writeTypeSuffixForScalar(value, jgen);
253
252
  }
253
+
254
+ enum RUBYCLASS {
255
+ String,
256
+ Float,
257
+ BigDecimal,
258
+ Time,
259
+ Array,
260
+ Hash,
261
+ Fixnum,
262
+ Bignum,
263
+ Date,
264
+ Symbol,
265
+ Struct,
266
+ TrueClass,
267
+ FalseClass
268
+ }
254
269
  }
@@ -1,33 +1,24 @@
1
1
  package com.jrjackson;
2
2
 
3
3
  import com.fasterxml.jackson.core.JsonGenerator;
4
- import java.io.IOException;
5
- import java.util.*;
6
-
7
- import java.math.BigDecimal;
8
- import java.math.BigInteger;
9
-
10
4
  import org.joda.time.DateTime;
11
5
  import org.joda.time.DateTimeZone;
12
6
  import org.joda.time.format.DateTimeFormat;
13
7
  import org.joda.time.format.DateTimeFormatter;
14
- import org.jruby.Ruby;
15
- import org.jruby.RubyArray;
16
- import org.jruby.RubyBignum;
17
- import org.jruby.RubyBoolean;
18
- import org.jruby.RubyFixnum;
19
- import org.jruby.RubyFloat;
20
- import org.jruby.RubyHash;
21
- import org.jruby.RubyObject;
22
- import org.jruby.RubyString;
23
- import org.jruby.RubySymbol;
24
-
25
- import org.jruby.javasupport.JavaUtil;
8
+ import org.jruby.*;
26
9
  import org.jruby.ext.bigdecimal.RubyBigDecimal;
10
+ import org.jruby.javasupport.JavaUtil;
27
11
  import org.jruby.runtime.builtin.IRubyObject;
28
12
  import org.jruby.util.ByteList;
29
13
  import org.jruby.util.SafeDoubleParser;
30
14
 
15
+ import java.io.IOException;
16
+ import java.math.BigDecimal;
17
+ import java.math.BigInteger;
18
+ import java.util.List;
19
+ import java.util.Locale;
20
+ import java.util.Map;
21
+
31
22
  public class RubyUtils {
32
23
 
33
24
  private final static DateTimeFormatter FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z").withLocale(Locale.ENGLISH);
@@ -107,6 +98,14 @@ public class RubyUtils {
107
98
  return hash;
108
99
  }
109
100
 
101
+ public static boolean isBasicObjectOrSubclass(IRubyObject object) {
102
+ List<IRubyObject> list = object.getMetaClass().getAncestorList();
103
+ for (IRubyObject entry : list) {
104
+ if("Kernel".equalsIgnoreCase(entry.toString())) return false;
105
+ }
106
+ return true;
107
+ }
108
+
110
109
  public static String jodaTimeString(DateTime dt) {
111
110
  // copied from the RubyTime to_s method
112
111
  // to prevent the double handling of a String -> RubyString -> String
@@ -192,7 +192,7 @@ public class SchParse extends StreamParse {
192
192
  }
193
193
 
194
194
  }
195
- // System.out.println("--- callAddValue final ---");
195
+ // System.out.println("--- addRubyValue final ---");
196
196
  // if (px != null) {
197
197
  // System.out.println("-------- parent --------");
198
198
  // System.out.println(px.getTypeDesc());
@@ -15,18 +15,13 @@ require 'time'
15
15
  require 'date'
16
16
 
17
17
  class JrJacksonTest < Test::Unit::TestCase
18
- # def test_serialize_date
19
- # # default date format
20
- # time_string = "2014-12-18 18:18:18 +0000"
21
- # source_time = Time.parse(time_string)
22
- # # source_time = Date.today
23
- # serialized_output = JrJackson::Json.dump({current_time: source_time})
24
- # assert_equal %Q{{"current_time":"#{time_string}"}}, serialized_output
25
- # end
26
- # end
27
18
  class Test::Unit::CustomObj
28
19
  end
29
20
 
21
+ class Test::Unit::NullObj < BasicObject
22
+ def nil?() true; end
23
+ end
24
+
30
25
  class ToJsonData
31
26
  attr_reader :one, :two, :six
32
27
  def initialize(a,b,c)
@@ -470,24 +465,32 @@ class JrJacksonTest < Test::Unit::TestCase
470
465
 
471
466
  end
472
467
 
473
- def test_cannot_serialize_object
474
- err = assert_raises(JrJackson::ParseError) { JrJackson::Json.dump({"foo" => Object.new}) }
475
- assert_match /Cannot serialize instance of: Object/, err.message
468
+ def test_can_serialize_object
469
+ obj = Object.new
470
+ actual = JrJackson::Json.dump({"foo" => obj})
471
+ assert_equal "{\"foo\":\"#{obj}\"}", actual
472
+ end
473
+
474
+ def test_can_serialize_basic_object
475
+ obj = BasicObject.new
476
+ actual = JrJackson::Json.dump({"foo" => obj})
477
+ assert_equal "{\"foo\":\"#<BasicObject>\"}", actual
476
478
  end
477
479
 
478
- def test_cannot_serialize_basic_object
479
- err = assert_raises(JrJackson::ParseError) { JrJackson::Json.dump({"foo" => BasicObject.new}) }
480
- assert_match /Cannot serialize instance of: BasicObject/, err.message
480
+ def test_can_serialize_basic_object_subclass
481
+ obj = Test::Unit::NullObj.new
482
+ actual = JrJackson::Json.dump({"foo" => obj})
483
+ assert_equal "{\"foo\":\"#<Test::Unit::NullObj>\"}", actual
481
484
  end
482
485
 
483
- def test_cannot_serialize_custom_object
484
- err = assert_raises(JrJackson::ParseError) { JrJackson::Json.dump({"foo" => Test::Unit::CustomObj.new}) }
485
- assert_match /Cannot serialize instance of: Test::Unit::CustomObj/, err.message
486
+ def test_can_serialize_custom_object
487
+ obj = Test::Unit::CustomObj.new
488
+ actual = JrJackson::Json.dump({"foo" => obj})
489
+ assert_equal "{\"foo\":\"#{obj}\"}", actual
486
490
  end
487
491
 
488
492
  def test_supports_pretty_printing
489
493
  object = {"foo" => 5, "utf8" => "żółć"}
490
-
491
494
  actual = JrJackson::Json.dump(object, :pretty => true)
492
495
  assert_equal "{\n \"foo\" : 5,\n \"utf8\" : \"żółć\"\n}", actual
493
496
  end
@@ -518,6 +521,20 @@ class JrJacksonTest < Test::Unit::TestCase
518
521
  assert_equal expected, actual
519
522
  end
520
523
 
524
+ def test_can_serialize_exceptions
525
+ e = StandardError.new("Something immensely bad happened")
526
+ object = {'error' => e}
527
+
528
+ actual = JrJackson::Json.dump(object)
529
+ assert_equal "{\"error\":\"#{e.inspect}\"}", actual
530
+ end
531
+
532
+ def test_can_serialize_class
533
+ object = {"foo" => BasicObject}
534
+ actual = JrJackson::Json.dump(object)
535
+ assert_equal "{\"foo\":\"#{BasicObject.inspect}\"}", actual
536
+ end
537
+
521
538
  # -----------------------------
522
539
 
523
540
  def assert_bigdecimal_equal(expected, actual)
metadata CHANGED
@@ -1,61 +1,61 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jrjackson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - Guy Boertje
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-09 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ~>
18
17
  - !ruby/object:Gem::Version
19
18
  version: '1.10'
20
- type: :development
19
+ name: bundler
21
20
  prerelease: false
21
+ type: :development
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
28
- name: jar-dependencies
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - "<"
30
+ - - <
32
31
  - !ruby/object:Gem::Version
33
32
  version: '2.0'
34
- - - ">="
33
+ - - '>='
35
34
  - !ruby/object:Gem::Version
36
35
  version: 0.3.2
37
- type: :development
36
+ name: jar-dependencies
38
37
  prerelease: false
38
+ type: :development
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - "<"
41
+ - - <
42
42
  - !ruby/object:Gem::Version
43
43
  version: '2.0'
44
- - - ">="
44
+ - - '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.3.2
47
47
  - !ruby/object:Gem::Dependency
48
- name: ruby-maven
49
48
  requirement: !ruby/object:Gem::Requirement
50
49
  requirements:
51
- - - "~>"
50
+ - - ~>
52
51
  - !ruby/object:Gem::Version
53
52
  version: 3.3.10
54
- type: :development
53
+ name: ruby-maven
55
54
  prerelease: false
55
+ type: :development
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ~>
59
59
  - !ruby/object:Gem::Version
60
60
  version: 3.3.10
61
61
  description: A mostly native JRuby wrapper for the java jackson json processor jar
@@ -65,9 +65,9 @@ executables: []
65
65
  extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
- - ".__jrubyrc"
69
- - ".gitignore"
70
- - ".mvn/extensions.xml"
68
+ - .__jrubyrc
69
+ - .gitignore
70
+ - .mvn/extensions.xml
71
71
  - Gemfile
72
72
  - Mavenfile
73
73
  - README.md
@@ -75,15 +75,13 @@ files:
75
75
  - alt_bench.rb
76
76
  - changelog.md
77
77
  - jrjackson.gemspec
78
- - lib/com/fasterxml/jackson/core/jackson-annotations/2.7.1/jackson-annotations-2.7.1.jar
79
- - lib/com/fasterxml/jackson/core/jackson-core/2.7.1/jackson-core-2.7.1.jar
80
- - lib/com/fasterxml/jackson/core/jackson-databind/2.7.1/jackson-databind-2.7.1.jar
81
- - lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.6.3/jackson-module-afterburner-2.6.3.jar
82
- - lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.7.1/jackson-module-afterburner-2.7.1.jar
78
+ - lib/com/fasterxml/jackson/core/jackson-annotations/2.7.3/jackson-annotations-2.7.3.jar
79
+ - lib/com/fasterxml/jackson/core/jackson-core/2.7.3/jackson-core-2.7.3.jar
80
+ - lib/com/fasterxml/jackson/core/jackson-databind/2.7.3/jackson-databind-2.7.3.jar
81
+ - lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.7.3/jackson-module-afterburner-2.7.3.jar
83
82
  - lib/jrjackson.rb
84
83
  - lib/jrjackson/build_info.rb
85
- - lib/jrjackson/jars/jrjackson-1.2.18.jar
86
- - lib/jrjackson/jars/jrjackson-1.2.7.jar
84
+ - lib/jrjackson/jars/jrjackson-1.2.19.jar
87
85
  - lib/jrjackson/jrjackson.rb
88
86
  - lib/jrjackson_jars.rb
89
87
  - lib/require_relative_patch.rb
@@ -135,28 +133,29 @@ homepage: http://github.com/guyboertje/jrjackson
135
133
  licenses:
136
134
  - Apache License 2.0
137
135
  metadata: {}
138
- post_install_message:
136
+ post_install_message:
139
137
  rdoc_options: []
140
138
  require_paths:
141
139
  - lib
142
140
  required_ruby_version: !ruby/object:Gem::Requirement
143
141
  requirements:
144
- - - ">="
142
+ - - '>='
145
143
  - !ruby/object:Gem::Version
146
144
  version: '0'
147
145
  required_rubygems_version: !ruby/object:Gem::Requirement
148
146
  requirements:
149
- - - ">="
147
+ - - '>='
150
148
  - !ruby/object:Gem::Version
151
149
  version: '0'
152
150
  requirements:
153
- - jar com.fasterxml.jackson.core:jackson-core, 2.7.1
154
- - jar com.fasterxml.jackson.core:jackson-annotations, 2.7.1
155
- - jar com.fasterxml.jackson.core:jackson-databind, 2.7.1
156
- - jar com.fasterxml.jackson.module:jackson-module-afterburner, 2.7.1
157
- rubyforge_project:
158
- rubygems_version: 2.4.5
159
- signing_key:
151
+ - jar com.fasterxml.jackson.core:jackson-core, 2.7.3
152
+ - jar com.fasterxml.jackson.core:jackson-annotations, 2.7.3
153
+ - jar com.fasterxml.jackson.core:jackson-databind, 2.7.3
154
+ - jar com.fasterxml.jackson.module:jackson-module-afterburner, 2.7.3
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.8
157
+ signing_key:
160
158
  specification_version: 4
161
159
  summary: A JRuby wrapper for the java jackson json processor jar
162
160
  test_files: []
161
+ has_rdoc:
Binary file