jrjackson 0.2.8 → 0.2.9

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: 40a6bbd8555b9dca8cf37b6e7e2f41692ae2bd2b
4
- data.tar.gz: af10130421ae850aea53f6b8396de32530605655
3
+ metadata.gz: a0da8217b380c2b90375f404bd62e1bd1fd9cfac
4
+ data.tar.gz: bef6c6e1bd90a0c8eb5159b3499774f46b08923d
5
5
  SHA512:
6
- metadata.gz: bab3ca8847f2dbe92becd2fee1c201a0abd72378c922b0814920cba71ff8390f1fb9237ff1efa32c40ffbf8678d7fa3f255b9e85f45932fd57523de6c5982d2a
7
- data.tar.gz: ae557540edc4d20a2e993da24f81d3ea35a092a2dd76b28815bede1ce9cac5a477aa9106277067749bc0a3a3487cc6a264b10d1fb10e09697a913868a6f33305
6
+ metadata.gz: 393220a4be40ca38b4147fb62d5e618c423b99ca859895b3da08e671482224dc9f4b9946f58d6ddc2c26699b681398e3c082950c37c8d0391996c8e3c3da3735
7
+ data.tar.gz: d0020e8cfe4fa216c2bf4015f607123ff119d07df45d44057e362a66c57a158818a07a262c90820e3dbde4de0d8d8a52d868b1434b4bb547a4850368ba9b28e2
data/.jrubyrc CHANGED
@@ -87,7 +87,7 @@ invokedynamic.invocation=true
87
87
 
88
88
  # Use SwitchPoint for class modification guards on invocations.
89
89
  # Options: [true, false], Default: true.
90
- invokedynamic.invocation.switchpoint=true
90
+ # invokedynamic.invocation.switchpoint=true
91
91
 
92
92
  # Also bind indirect method invokers to invokedynamic.
93
93
  # Options: [true, false], Default: true.
@@ -4,7 +4,7 @@
4
4
  <groupId>com.jrjackson.jruby</groupId>
5
5
  <artifactId>jrjackson</artifactId>
6
6
  <name>jrjackson</name>
7
- <version>1.2.11</version>
7
+ <version>1.2.12</version>
8
8
  <url>http://maven.apache.org</url>
9
9
  <build>
10
10
  <plugins>
data/jrjackson.gemspec CHANGED
@@ -7,7 +7,7 @@ require 'jrjackson/build_info'
7
7
  Gem::Specification.new do |s|
8
8
  s.name = 'jrjackson'
9
9
  s.version = JrJackson::BuildInfo.version
10
- s.date = '2013-10-12'
10
+ s.date = JrJackson::BuildInfo.release_date
11
11
  s.platform = Gem::Platform::RUBY
12
12
  s.authors = ['Guy Boertje']
13
13
  s.email = ['guyboertje@gmail.com']
@@ -1,7 +1,11 @@
1
1
  module JrJackson
2
2
  module BuildInfo
3
3
  def self.version
4
- '0.2.8'
4
+ '0.2.9'
5
+ end
6
+
7
+ def self.release_date
8
+ '2015-06-24'
5
9
  end
6
10
 
7
11
  def self.files
@@ -3,8 +3,8 @@ unless RUBY_PLATFORM =~ /java/
3
3
  exit 255
4
4
  end
5
5
 
6
- require_relative "jars/jrjackson-1.2.11.jar"
7
- # require_relative "linked/jrjackson-1.2.11.jar"
6
+ require_relative "jars/jrjackson-1.2.12.jar"
7
+ # require_relative "linked/jrjackson-1.2.12.jar"
8
8
 
9
9
  require 'com/jrjackson/jr_jackson'
10
10
 
data/pom.xml CHANGED
@@ -5,7 +5,7 @@
5
5
  <groupId>com.jrjackson.jruby</groupId>
6
6
  <artifactId>jrjackson</artifactId>
7
7
  <packaging>jar</packaging>
8
- <version>1.2.11</version>
8
+ <version>1.2.12</version>
9
9
  <name>jrjackson</name>
10
10
  <url>http://maven.apache.org</url>
11
11
 
@@ -126,11 +126,11 @@ public class JrJacksonRaw extends RubyObject {
126
126
  Object obj = args[0].toJava(Object.class);
127
127
  RubyHash options = (args.length <= 1) ? RubyHash.newHash(_ruby) : args[1].convertToHash();
128
128
  String format = (String) options.get(RubyUtils.rubySymbol(_ruby, "date_format"));
129
-
129
+
130
130
  ObjectMapper mapper = RubyJacksonModule.mappedAs("raw", _ruby);
131
131
  // same format as Ruby Time #to_s
132
132
  SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
133
-
133
+
134
134
  if (format != null) {
135
135
  simpleFormat = new SimpleDateFormat(format);
136
136
  String timezone = (String) options.get(RubyUtils.rubySymbol(_ruby, "timezone"));
@@ -139,7 +139,6 @@ public class JrJacksonRaw extends RubyObject {
139
139
  }
140
140
  }
141
141
  mapper.setDateFormat(simpleFormat);
142
-
143
142
  try {
144
143
  String s = mapper.writeValueAsString(obj);
145
144
  return RubyUtils.rubyString(_ruby, s);
@@ -9,12 +9,16 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer;
9
9
  import com.fasterxml.jackson.databind.SerializerProvider;
10
10
 
11
11
  import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
12
+ import java.math.BigDecimal;
13
+ import java.math.BigInteger;
12
14
 
13
15
  import org.jruby.*;
16
+ import org.jruby.ext.bigdecimal.RubyBigDecimal;
14
17
  import org.jruby.runtime.ThreadContext;
15
18
  import org.jruby.internal.runtime.methods.DynamicMethod;
19
+ import org.jruby.runtime.builtin.IRubyObject;
16
20
 
17
- public class RubyAnySerializer extends StdSerializer<RubyObject> {
21
+ public class RubyAnySerializer extends StdSerializer<IRubyObject> {
18
22
 
19
23
  /**
20
24
  * Singleton instance to use.
@@ -23,29 +27,31 @@ public class RubyAnySerializer extends StdSerializer<RubyObject> {
23
27
  private static final HashMap<Class, Class> class_maps = new HashMap<Class, Class>();
24
28
 
25
29
  static {
30
+ // not need now - clean up required
26
31
  class_maps.put(RubyBoolean.class, Boolean.class);
32
+ class_maps.put(RubyFloat.class, Double.class);
33
+ class_maps.put(RubyFixnum.class, Long.class);
34
+ class_maps.put(RubyBignum.class, BigInteger.class);
35
+ class_maps.put(RubyBigDecimal.class, BigDecimal.class);
27
36
  }
28
37
 
29
38
  public RubyAnySerializer() {
30
- super(RubyObject.class);
39
+ super(IRubyObject.class);
31
40
  }
32
41
 
33
42
  private Class<?> rubyJavaClassLookup(Class target) {
34
- Class<?> val = class_maps.get(target);
35
- if (val == null) {
36
- return Object.class;
37
- }
38
- return val;
43
+ return class_maps.get(target);
39
44
  }
40
45
 
41
- private void serializeUnknownRubyObject(ThreadContext ctx, RubyObject rubyObject, JsonGenerator jgen, SerializerProvider provider)
46
+ private void serializeUnknownRubyObject(ThreadContext ctx, IRubyObject rubyObject, JsonGenerator jgen, SerializerProvider provider)
42
47
  throws IOException, JsonGenerationException {
43
48
  RubyClass meta = rubyObject.getMetaClass();
44
49
 
45
50
  DynamicMethod method = meta.searchMethod("to_time");
46
51
  if (!method.isUndefined()) {
47
- RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_time");
48
- provider.defaultSerializeValue(obj, jgen);
52
+ RubyTime dt = (RubyTime) method.call(ctx, rubyObject, meta, "to_time");
53
+ String time = RubyUtils.jodaTimeString(dt.getDateTime());
54
+ jgen.writeString(time);
49
55
  return;
50
56
  }
51
57
 
@@ -84,25 +90,68 @@ public class RubyAnySerializer extends StdSerializer<RubyObject> {
84
90
  }
85
91
 
86
92
  @Override
87
- public void serialize(RubyObject value, JsonGenerator jgen, SerializerProvider provider)
93
+ public void serialize(IRubyObject value, JsonGenerator jgen, SerializerProvider provider)
88
94
  throws IOException, JsonGenerationException {
89
95
  ThreadContext ctx = value.getRuntime().getCurrentContext();
90
- if (value instanceof RubySymbol || value instanceof RubyString) {
96
+ if (value.isNil()) {
97
+
98
+ jgen.writeNull(); // for RubyNil and NullObjects
99
+
100
+ } else if (value instanceof RubyString) {
101
+
102
+ jgen.writeString(value.toString());
103
+
104
+ } else if (value instanceof RubySymbol) {
105
+
91
106
  jgen.writeString(value.toString());
107
+
108
+ } else if (value instanceof RubyBoolean) {
109
+
110
+ jgen.writeBoolean(value.isTrue());
111
+
112
+ } else if (value instanceof RubyFloat) {
113
+
114
+ jgen.writeNumber(RubyNumeric.num2dbl(value));
115
+
116
+ } else if (value instanceof RubyFixnum) {
117
+
118
+ jgen.writeNumber(RubyNumeric.num2long(value));
119
+
120
+ } else if (value instanceof RubyBignum) {
121
+
122
+ jgen.writeNumber(((RubyBignum) value).getBigIntegerValue());
123
+
124
+ } else if (value instanceof RubyBigDecimal) {
125
+
126
+ jgen.writeNumber(((RubyBigDecimal) value).getBigDecimalValue());
127
+
92
128
  } else if (value instanceof RubyHash) {
93
- provider.findTypedValueSerializer(Map.class, true, null).serialize(value, jgen, provider);
129
+
130
+ provider.findTypedValueSerializer(value.getJavaClass(), true, null).serialize(value, jgen, provider);
131
+
94
132
  } else if (value instanceof RubyArray) {
95
- provider.findTypedValueSerializer(List.class, true, null).serialize(value, jgen, provider);
133
+
134
+ provider.findTypedValueSerializer(value.getJavaClass(), true, null).serialize(value, jgen, provider);
135
+
96
136
  } else if (value instanceof RubyStruct) {
97
- RubyObject obj = (RubyObject)value.callMethod(ctx, "to_a");
98
- provider.findTypedValueSerializer(List.class, true, null).serialize(obj, jgen, provider);
137
+
138
+ IRubyObject obj = value.callMethod(ctx, "to_a");
139
+ provider.findTypedValueSerializer(obj.getJavaClass(), true, null).serialize(obj, jgen, provider);
140
+
99
141
  } else {
100
- Object val = value.toJava(rubyJavaClassLookup(value.getClass()));
101
- if (val instanceof RubyObject) {
102
- serializeUnknownRubyObject(ctx, (RubyObject) val, jgen, provider);
142
+
143
+ Class<?> cls = rubyJavaClassLookup(value.getClass());
144
+ if (cls != null) {
145
+ Object val = value.toJava(cls);
146
+ if (val != null) {
147
+ provider.defaultSerializeValue(val, jgen);
148
+ } else {
149
+ serializeUnknownRubyObject(ctx, value, jgen, provider);
150
+ }
103
151
  } else {
104
- provider.defaultSerializeValue(val, jgen);
152
+ serializeUnknownRubyObject(ctx, value, jgen, provider);
105
153
  }
154
+
106
155
  }
107
156
  }
108
157
 
@@ -117,7 +166,7 @@ public class RubyAnySerializer extends StdSerializer<RubyObject> {
117
166
  * @throws com.fasterxml.jackson.core.JsonGenerationException
118
167
  */
119
168
  @Override
120
- public void serializeWithType(RubyObject value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer)
169
+ public void serializeWithType(IRubyObject value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer)
121
170
  throws IOException, JsonGenerationException {
122
171
  typeSer.writeTypePrefixForScalar(value, jgen);
123
172
  serialize(value, jgen, provider);
@@ -1,6 +1,5 @@
1
1
  package com.jrjackson;
2
2
 
3
- import java.text.SimpleDateFormat;
4
3
 
5
4
  import org.jruby.*;
6
5
 
@@ -9,11 +8,12 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
9
8
  import com.fasterxml.jackson.databind.SerializationFeature;
10
9
  import com.fasterxml.jackson.core.util.VersionUtil;
11
10
  import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
11
+ import org.jruby.runtime.builtin.IRubyObject;
12
12
 
13
13
  public class RubyJacksonModule extends SimpleModule {
14
14
 
15
15
  private static final ObjectMapper static_mapper = new ObjectMapper().registerModule(
16
- new RubyJacksonModule().addSerializer(RubyObject.class, RubyAnySerializer.instance)
16
+ new RubyJacksonModule().addSerializer(IRubyObject.class, RubyAnySerializer.instance)
17
17
  );
18
18
 
19
19
  static {
@@ -49,7 +49,7 @@ public class RubyJacksonModule extends SimpleModule {
49
49
 
50
50
  public static SimpleModule asSym(Ruby ruby) {
51
51
  return new RubyJacksonModule().addSerializer(
52
- RubyObject.class, RubyAnySerializer.instance
52
+ IRubyObject.class, RubyAnySerializer.instance
53
53
  ).addDeserializer(
54
54
  Object.class, new RubyObjectDeserializer().withRuby(ruby).setSymbolStrategy()
55
55
  );
@@ -57,7 +57,7 @@ public class RubyJacksonModule extends SimpleModule {
57
57
 
58
58
  public static SimpleModule asStr(Ruby ruby) {
59
59
  return new RubyJacksonModule().addSerializer(
60
- RubyObject.class, RubyAnySerializer.instance
60
+ IRubyObject.class, RubyAnySerializer.instance
61
61
  ).addDeserializer(
62
62
  Object.class, new RubyObjectDeserializer().withRuby(ruby).setStringStrategy()
63
63
  );
@@ -4,7 +4,10 @@ import java.util.*;
4
4
 
5
5
  import java.math.BigDecimal;
6
6
  import java.math.BigInteger;
7
- import java.nio.CharBuffer;
7
+ import org.joda.time.DateTime;
8
+ import org.joda.time.DateTimeZone;
9
+ import org.joda.time.format.DateTimeFormat;
10
+ import org.joda.time.format.DateTimeFormatter;
8
11
 
9
12
  import org.jruby.*;
10
13
  import org.jruby.javasupport.JavaUtil;
@@ -13,6 +16,9 @@ import org.jruby.util.SafeDoubleParser;
13
16
 
14
17
  public class RubyUtils {
15
18
 
19
+ private final static DateTimeFormatter FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z").withLocale(Locale.ENGLISH);
20
+ private final static DateTimeFormatter UTC_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss 'UTC'").withLocale(Locale.ENGLISH);
21
+
16
22
  public static RubyObject rubyObject(Ruby ruby, Object node) {
17
23
  return (RubyObject) JavaUtil.convertJavaToRuby(ruby, node);
18
24
  }
@@ -32,7 +38,7 @@ public class RubyUtils {
32
38
  public static RubySymbol rubySymbol(Ruby ruby, String node) {
33
39
  return RubySymbol.newSymbol(ruby, node);
34
40
  }
35
-
41
+
36
42
  public static RubyArray rubyArray(Ruby ruby, Object[] arg) {
37
43
  return (RubyArray) JavaUtil.convertJavaToRuby(ruby, arg);
38
44
  }
@@ -73,4 +79,33 @@ public class RubyUtils {
73
79
  public static RubyBoolean rubyBoolean(Ruby ruby, Boolean arg) {
74
80
  return ruby.newBoolean(arg);
75
81
  }
82
+
83
+ public static String jodaTimeString(DateTime dt) {
84
+ // copied from the RubyTime to_s method
85
+ // to prevent the double handling of a String -> RubyString -> String
86
+ DateTimeFormatter simpleDateFormat;
87
+ if (dt.getZone() == DateTimeZone.UTC) {
88
+ simpleDateFormat = UTC_FORMATTER;
89
+ } else {
90
+ simpleDateFormat = FORMATTER;
91
+ }
92
+
93
+ return simpleDateFormat.print(dt);
94
+
95
+ // JrJackson: no access to private boolean isTzRelative
96
+
97
+ // String result = simpleDateFormat.print(dt);
98
+ //
99
+ // if (isTzRelative) {
100
+ // // display format needs to invert the UTC offset if this object was
101
+ // // created with a specific offset in the 7-arg form of #new
102
+ // DateTimeZone dtz = dt.getZone();
103
+ // int offset = dtz.toTimeZone().getOffset(dt.getMillis());
104
+ // DateTimeZone invertedDTZ = DateTimeZone.forOffsetMillis(offset);
105
+ // DateTime invertedDT = dt.withZone(invertedDTZ);
106
+ // result = simpleDateFormat.print(invertedDT);
107
+ // }
108
+ //
109
+ // return result;
110
+ }
76
111
  }
@@ -204,6 +204,16 @@ class JrJacksonTest < Test::Unit::TestCase
204
204
  assert_bigdecimal_similar expected, actual
205
205
  end
206
206
 
207
+ def test_cannot_serialize_object
208
+ err = assert_raises(JrJackson::ParseError) { JrJackson::Json.dump({"foo" => Object.new}) }
209
+ assert_match /Cannot find Serializer for class: org.jruby.RubyObject/, err.message
210
+ end
211
+
212
+ def test_cannot_serialize_basic_object
213
+ err = assert_raises(JrJackson::ParseError) { JrJackson::Json.dump({"foo" => BasicObject.new}) }
214
+ assert_match /Cannot find Serializer for class: org.jruby.RubyBasicObject/, err.message
215
+ end
216
+
207
217
  def assert_bigdecimal_equal(expected, actual)
208
218
  assert_equal expected, actual
209
219
  assert_equal expected.class, actual.class
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.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Boertje
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-12 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -41,7 +41,7 @@ files:
41
41
  - jrjackson.gemspec
42
42
  - lib/jrjackson.rb
43
43
  - lib/jrjackson/build_info.rb
44
- - lib/jrjackson/jars/jrjackson-1.2.11.jar
44
+ - lib/jrjackson/jars/jrjackson-1.2.12.jar
45
45
  - lib/jrjackson/jrjackson.rb
46
46
  - lib/require_relative_patch.rb
47
47
  - pom.xml
@@ -79,9 +79,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.2.2
82
+ rubygems_version: 2.4.5
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: A JRuby wrapper for the java jackson json processor jar
86
86
  test_files: []
87
- has_rdoc: