jrjackson 0.4.18-java → 0.4.19-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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/jrjackson.gemspec +1 -2
  3. data/lib/com/fasterxml/jackson/core/jackson-annotations/{2.15.2/jackson-annotations-2.15.2.jar → 2.15.4/jackson-annotations-2.15.4.jar} +0 -0
  4. data/lib/com/fasterxml/jackson/core/jackson-core/{2.15.2/jackson-core-2.15.2.jar → 2.15.4/jackson-core-2.15.4.jar} +0 -0
  5. data/lib/com/fasterxml/jackson/core/jackson-databind/{2.15.2/jackson-databind-2.15.2.jar → 2.15.4/jackson-databind-2.15.4.jar} +0 -0
  6. data/lib/com/fasterxml/jackson/module/jackson-module-afterburner/{2.15.2/jackson-module-afterburner-2.15.2.jar → 2.15.4/jackson-module-afterburner-2.15.4.jar} +0 -0
  7. data/lib/jrjackson/build_info.rb +8 -8
  8. data/lib/jrjackson/jars/{jrjackson-1.2.35.jar → jrjackson-1.2.36.jar} +0 -0
  9. data/lib/jrjackson_jars.rb +8 -8
  10. data/pom.xml +47 -10
  11. metadata +13 -78
  12. data/.gitignore +0 -16
  13. data/.jrubyr_c +0 -433
  14. data/Gemfile +0 -13
  15. data/Mavenfile +0 -25
  16. data/Rakefile +0 -39
  17. data/alt_bench.rb +0 -46
  18. data/changelog.md +0 -181
  19. data/profiling/profiled.rb +0 -15
  20. data/run_all_individual_bench.sh +0 -25
  21. data/run_jruby_individual_bench.sh +0 -20
  22. data/run_mri_individual_bench.sh +0 -7
  23. data/src/main/java/com/jrjackson/IParseHandler.java +0 -53
  24. data/src/main/java/com/jrjackson/JavaBigDecimalValueConverter.java +0 -17
  25. data/src/main/java/com/jrjackson/JavaBigIntValueConverter.java +0 -17
  26. data/src/main/java/com/jrjackson/JavaConverter.java +0 -10
  27. data/src/main/java/com/jrjackson/JavaFloatValueConverter.java +0 -16
  28. data/src/main/java/com/jrjackson/JavaHandler.java +0 -118
  29. data/src/main/java/com/jrjackson/JavaLongValueConverter.java +0 -16
  30. data/src/main/java/com/jrjackson/JjParse.java +0 -139
  31. data/src/main/java/com/jrjackson/JrJacksonBase.java +0 -152
  32. data/src/main/java/com/jrjackson/JrJacksonJava.java +0 -81
  33. data/src/main/java/com/jrjackson/JrJacksonRaw.java +0 -108
  34. data/src/main/java/com/jrjackson/JrJacksonRuby.java +0 -89
  35. data/src/main/java/com/jrjackson/JrJacksonSaj.java +0 -26
  36. data/src/main/java/com/jrjackson/JrJacksonSch.java +0 -25
  37. data/src/main/java/com/jrjackson/JrJacksonService.java +0 -38
  38. data/src/main/java/com/jrjackson/JrParse.java +0 -142
  39. data/src/main/java/com/jrjackson/ParseError.java +0 -16
  40. data/src/main/java/com/jrjackson/RubyAnySerializer.java +0 -291
  41. data/src/main/java/com/jrjackson/RubyBigDecimalValueConverter.java +0 -18
  42. data/src/main/java/com/jrjackson/RubyBigIntValueConverter.java +0 -21
  43. data/src/main/java/com/jrjackson/RubyConverter.java +0 -12
  44. data/src/main/java/com/jrjackson/RubyDateFormat.java +0 -34
  45. data/src/main/java/com/jrjackson/RubyFloatValueConverter.java +0 -18
  46. data/src/main/java/com/jrjackson/RubyHandler.java +0 -119
  47. data/src/main/java/com/jrjackson/RubyIntValueConverter.java +0 -18
  48. data/src/main/java/com/jrjackson/RubyJacksonModule.java +0 -80
  49. data/src/main/java/com/jrjackson/RubyKeyConverter.java +0 -12
  50. data/src/main/java/com/jrjackson/RubyNameConverter.java +0 -9
  51. data/src/main/java/com/jrjackson/RubyObjectDeserializer.java +0 -182
  52. data/src/main/java/com/jrjackson/RubyStringConverter.java +0 -18
  53. data/src/main/java/com/jrjackson/RubyStringKeyConverter.java +0 -15
  54. data/src/main/java/com/jrjackson/RubyStringNameConverter.java +0 -12
  55. data/src/main/java/com/jrjackson/RubySymbolKeyConverter.java +0 -15
  56. data/src/main/java/com/jrjackson/RubySymbolNameConverter.java +0 -12
  57. data/src/main/java/com/jrjackson/RubyUtils.java +0 -149
  58. data/src/main/java/com/jrjackson/SajParse.java +0 -169
  59. data/src/main/java/com/jrjackson/SchParse.java +0 -209
  60. data/src/main/java/com/jrjackson/StreamParse.java +0 -66
  61. data/src/test/java/com/jrjackson/RubyAnySerializerTest.java +0 -56
  62. data/test/jrjackson_test.rb +0 -578
@@ -1,291 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonGenerationException;
4
- import com.fasterxml.jackson.core.JsonGenerator;
5
- import com.fasterxml.jackson.databind.JsonSerializer;
6
- import com.fasterxml.jackson.databind.SerializerProvider;
7
- import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
8
- import org.jruby.RubyArray;
9
- import org.jruby.RubyClass;
10
- import org.jruby.RubyException;
11
- import org.jruby.RubyHash;
12
- import org.jruby.RubyNumeric;
13
- import org.jruby.RubyObject;
14
- import org.jruby.RubyString;
15
- import org.jruby.RubyStruct;
16
- import org.jruby.RubyTime;
17
- import org.jruby.ext.bigdecimal.RubyBigDecimal;
18
- import org.jruby.internal.runtime.methods.DynamicMethod;
19
- import org.jruby.java.proxies.JavaProxy;
20
- import org.jruby.runtime.ThreadContext;
21
- import org.jruby.runtime.builtin.IRubyObject;
22
-
23
- import java.io.IOException;
24
- import java.text.DateFormat;
25
- import java.text.SimpleDateFormat;
26
-
27
-
28
- public class RubyAnySerializer extends JsonSerializer<IRubyObject> {
29
-
30
- /**
31
- * Singleton instance to use.""
32
- */
33
- public static final RubyAnySerializer instance = new RubyAnySerializer();
34
- private static final String HLT = "#<";
35
- private static final String CSP = ": ";
36
- private static final String GT = ">";
37
-
38
- private static final RUBYCLASS[] CLASS_NAMES = RUBYCLASS.values();
39
-
40
- public RubyAnySerializer() {
41
- // super(IRubyObject.class);
42
-
43
- }
44
-
45
- private void serializeUnknownRubyObject(ThreadContext ctx, IRubyObject rubyObject, JsonGenerator jgen, SerializerProvider provider)
46
- throws IOException, JsonGenerationException {
47
- RubyClass meta = rubyObject.getMetaClass();
48
-
49
- DynamicMethod method = meta.searchMethod("to_json_data");
50
- if (!method.isUndefined()) {
51
- RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_json_data");
52
- if (obj instanceof RubyString) {
53
- RubyUtils.writeBytes(obj, jgen);
54
- } else {
55
- serialize(obj, jgen, provider);
56
- }
57
- return;
58
- }
59
-
60
- method = meta.searchMethod("to_time");
61
- if (!method.isUndefined()) {
62
- RubyTime dt = (RubyTime) method.call(ctx, rubyObject, meta, "to_time");
63
- serializeTime(dt, jgen, provider);
64
- return;
65
- }
66
-
67
- method = meta.searchMethod("to_h");
68
- if (!method.isUndefined()) {
69
- RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_h");
70
- serializeHash(obj, jgen, provider);
71
- return;
72
- }
73
-
74
- method = meta.searchMethod("to_hash");
75
- if (!method.isUndefined()) {
76
- RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_hash");
77
- serializeHash(obj, jgen, provider);
78
- return;
79
- }
80
-
81
- method = meta.searchMethod("to_a");
82
- if (!method.isUndefined()) {
83
- RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_a");
84
- serializeArray(obj, jgen, provider);
85
- return;
86
- }
87
-
88
- method = meta.searchMethod("to_json");
89
- if (!method.isUndefined()) {
90
- RubyObject obj = (RubyObject) method.call(ctx, rubyObject, meta, "to_json");
91
- if (obj instanceof RubyString) {
92
- jgen.writeRawValue(obj.toString());
93
- } else {
94
- serialize(obj, jgen, provider);
95
- }
96
- return;
97
- }
98
-
99
- if (!RubyUtils.isBasicObjectOrSubclass(rubyObject) && rubyObject.respondsTo("to_s")) {
100
- String result = rubyObject.toString();
101
- jgen.writeString(result);
102
- } else {
103
- String name = meta.getRealClass().getName();
104
- StringBuilder sb = new StringBuilder(2 + name.length());
105
- sb.append(HLT).append(name).append(GT);
106
- jgen.writeString(sb.toString());
107
- }
108
- }
109
-
110
- @Override
111
- public void serialize(IRubyObject value, JsonGenerator jgen, SerializerProvider provider)
112
- throws IOException, JsonGenerationException {
113
-
114
- String rubyClassName = value.getType().getName();
115
-
116
- if (value.isNil()) {
117
- jgen.writeNull(); // for RubyNil and NullObjects
118
- return;
119
- }
120
-
121
- if (value instanceof JavaProxy) {
122
- provider.defaultSerializeValue(((JavaProxy) value).getObject(), jgen);
123
- return;
124
- }
125
-
126
- if (value instanceof RubyStruct) {
127
- IRubyObject obj = value.callMethod(value.getRuntime().getCurrentContext(), "to_a");
128
- serializeArray(obj, jgen, provider);
129
- return;
130
- }
131
-
132
- if (value instanceof RubyException) {
133
- RubyException re = (RubyException) value;
134
- String msg = re.message(value.getRuntime().getCurrentContext()).toString();
135
- StringBuilder sb = new StringBuilder(5 + rubyClassName.length() + msg.length());
136
- sb.append(HLT).append(rubyClassName).append(CSP).append(msg).append(GT);
137
- jgen.writeString(sb.toString());
138
- return;
139
- }
140
-
141
- if (value.isClass() || value.isModule()) {
142
- jgen.writeString(value.inspect().toString());
143
- return;
144
- }
145
-
146
- RUBYCLASS clazz = null;
147
-
148
- for(RUBYCLASS v : CLASS_NAMES) {
149
- if(rubyClassName.equals(v.name())) {
150
- clazz = v;
151
- break;
152
- }
153
- }
154
-
155
- if (clazz == null) {
156
- serializeUnknownRubyObject(value.getRuntime().getCurrentContext(), value, jgen, provider);
157
- return;
158
- }
159
-
160
- switch (clazz) {
161
- case Hash:
162
- serializeHash(value, jgen, provider);
163
- break;
164
- case Array:
165
- serializeArray(value, jgen, provider);
166
- break;
167
- case String:
168
- RubyUtils.writeBytes(value, jgen);
169
- break;
170
- case Symbol:
171
- case Date:
172
- // Date to_s -> yyyy-mm-dd
173
- RubyString s = value.asString();
174
- jgen.writeUTF8String(s.getBytes(), 0, s.size());
175
- break;
176
- case TrueClass:
177
- case FalseClass:
178
- jgen.writeBoolean(value.isTrue());
179
- break;
180
- case Float:
181
- jgen.writeNumber(RubyNumeric.num2dbl(value));
182
- break;
183
- case Bignum:
184
- case Fixnum:
185
- case Integer:
186
- if (value.getJavaClass() == long.class) {
187
- jgen.writeNumber(((RubyNumeric) value).getLongValue());
188
- } else {
189
- jgen.writeNumber(((RubyNumeric) value).getBigIntegerValue());
190
- }
191
- break;
192
- case BigDecimal:
193
- jgen.writeNumber(((RubyBigDecimal) value).getBigDecimalValue());
194
- break;
195
- case Time:
196
- serializeTime((RubyTime) value, jgen, provider);
197
- break;
198
- default:
199
- serializeUnknownRubyObject(value.getRuntime().getCurrentContext(), value, jgen, provider);
200
- break;
201
- }
202
- }
203
-
204
- private void serializeArray(IRubyObject value, JsonGenerator jgen, SerializerProvider provider)
205
- throws IOException, JsonGenerationException {
206
- // System.err.println("----->> RubyArray");
207
-
208
- RubyArray arr = (RubyArray) value;
209
- IRubyObject[] a = arr.toJavaArray();
210
- jgen.writeStartArray();
211
- for (IRubyObject val : a) {
212
- serialize(val, jgen, provider);
213
- }
214
- jgen.writeEndArray();
215
- }
216
-
217
- private void serializeHash(IRubyObject value, JsonGenerator jgen, SerializerProvider provider)
218
- throws IOException, JsonGenerationException {
219
- // System.err.println("----->> RubyHash");
220
-
221
- RubyHash h = (RubyHash) value;
222
- jgen.writeStartObject();
223
- for (Object o : h.directEntrySet()) {
224
- RubyHash.RubyHashEntry next = (RubyHash.RubyHashEntry) o;
225
- serializeKey((IRubyObject) next.getKey(), jgen, provider);
226
- serialize((IRubyObject) next.getValue(), jgen, provider);
227
- }
228
- jgen.writeEndObject();
229
- }
230
-
231
- private void serializeTime(RubyTime dt, JsonGenerator jgen, SerializerProvider provider)
232
- throws IOException, JsonGenerationException {
233
- DateFormat df = provider.getConfig().getDateFormat();
234
- if (df == null) {
235
- // DateFormat should always be set
236
- provider.defaultSerializeDateValue(dt.getJavaDate(), jgen);
237
- } // RWB Note: I believe this is no longer used
238
- else if (df instanceof RubyDateFormat) {
239
- // why another branch? I thought there was an easy win on to_s
240
- // maybe with jruby 9000
241
- RubyDateFormat clonedRubyDateFormat = (RubyDateFormat) df.clone();
242
- jgen.writeString(clonedRubyDateFormat.format(dt.getJavaDate()));
243
- } else {
244
- jgen.writeString(df.format(dt.getJavaDate()));
245
- }
246
- }
247
-
248
- private void serializeKey(IRubyObject key, JsonGenerator jgen, SerializerProvider provider)
249
- throws IOException, JsonGenerationException {
250
- if (key instanceof RubyString) {
251
- jgen.writeFieldName(((RubyString) key).decodeString());
252
- } else {
253
- // includes RubySymbol and non RubyString objects
254
- jgen.writeFieldName(key.toString());
255
- }
256
- }
257
-
258
- /**
259
- * Default implementation will write type prefix, call regular serialization method (since assumption is that value itself does not need JSON Array or Object start/end markers), and then write type suffix. This should work for most cases; some sub-classes may want to change this behavior.
260
- *
261
- * @param value
262
- * @param jgen
263
- * @param provider
264
- * @param typeSer
265
- * @throws java.io.IOException
266
- * @throws com.fasterxml.jackson.core.JsonGenerationException
267
- */
268
- @Override
269
- public void serializeWithType(IRubyObject value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer)
270
- throws IOException, JsonGenerationException {
271
- typeSer.writeTypePrefixForScalar(value, jgen);
272
- serialize(value, jgen, provider);
273
- typeSer.writeTypeSuffixForScalar(value, jgen);
274
- }
275
-
276
- enum RUBYCLASS {
277
- String,
278
- Fixnum,
279
- Integer,
280
- Hash,
281
- Array,
282
- Float,
283
- BigDecimal,
284
- Time,
285
- Bignum,
286
- Date,
287
- Symbol,
288
- TrueClass,
289
- FalseClass
290
- }
291
- }
@@ -1,18 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonParser;
4
- import java.io.IOException;
5
- import org.jruby.Ruby;
6
- import org.jruby.RubyObject;
7
-
8
- /**
9
- *
10
- * @author Guy Boertje
11
- */
12
- public class RubyBigDecimalValueConverter implements RubyConverter {
13
-
14
- @Override
15
- public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
16
- return RubyUtils.rubyBigDecimal(ruby, jp.getDecimalValue());
17
- }
18
- }
@@ -1,21 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonParser;
4
- import java.io.IOException;
5
- import org.jruby.Ruby;
6
- import org.jruby.RubyObject;
7
-
8
- /**
9
- *
10
- * @author Guy Boertje
11
- */
12
- public class RubyBigIntValueConverter implements RubyConverter {
13
-
14
- @Override
15
- public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
16
- if (jp.getNumberType() == JsonParser.NumberType.BIG_INTEGER) {
17
- return RubyUtils.rubyBignum(ruby, jp.getBigIntegerValue());
18
- }
19
- return RubyUtils.rubyFixnum(ruby, jp.getLongValue());
20
- }
21
- }
@@ -1,12 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.*;
4
-
5
- import java.io.IOException;
6
- import org.jruby.Ruby;
7
- import org.jruby.RubyObject;
8
-
9
- public interface RubyConverter {
10
-
11
- public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException;
12
- }
@@ -1,34 +0,0 @@
1
- /*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
- package com.jrjackson;
7
-
8
- import java.text.DateFormatSymbols;
9
- import java.text.SimpleDateFormat;
10
- import java.util.Locale;
11
-
12
- /**
13
- *
14
- * @author guy
15
- */
16
- public class RubyDateFormat extends SimpleDateFormat{
17
-
18
- public RubyDateFormat() {
19
- }
20
-
21
- public RubyDateFormat(String pattern) {
22
- super(pattern);
23
- }
24
-
25
- public RubyDateFormat(String pattern, Locale locale) {
26
- super(pattern, locale);
27
- }
28
-
29
- public RubyDateFormat(String pattern, DateFormatSymbols formatSymbols) {
30
-
31
- super(pattern, formatSymbols);
32
- }
33
-
34
- }
@@ -1,18 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonParser;
4
- import java.io.IOException;
5
- import org.jruby.Ruby;
6
- import org.jruby.RubyObject;
7
-
8
- /**
9
- *
10
- * @author Guy Boertje
11
- */
12
- public class RubyFloatValueConverter implements RubyConverter {
13
-
14
- @Override
15
- public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
16
- return RubyUtils.rubyFloat(ruby, jp.getDoubleValue());
17
- }
18
- }
@@ -1,119 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonParser;
4
- import java.io.IOException;
5
- import org.jruby.Ruby;
6
- import org.jruby.RubyArray;
7
- import org.jruby.RubyHash;
8
- import org.jruby.runtime.ThreadContext;
9
- import org.jruby.runtime.builtin.IRubyObject;
10
-
11
- /**
12
- *
13
- * @author Guy Boertje
14
- */
15
- public class RubyHandler implements IParseHandler<IRubyObject, RubyArray, RubyHash> {
16
-
17
- private final Ruby _ruby;
18
- private final ThreadContext _ctx;
19
- private final RubyNameConverter _keyConv;
20
- private final RubyConverter _intConv;
21
- private final RubyConverter _floatConv;
22
- private final RubyConverter _strConv;
23
- private IRubyObject _result;
24
-
25
- public RubyHandler(ThreadContext ctx,
26
- RubyNameConverter keyConverter,
27
- RubyConverter intConverter,
28
- RubyConverter floatConverter) {
29
-
30
- _ctx = ctx;
31
- _ruby = ctx.runtime;
32
- _keyConv = keyConverter;
33
- _intConv = intConverter;
34
- _floatConv = floatConverter;
35
- _strConv = new RubyStringConverter();
36
- }
37
-
38
- @Override
39
- public void addValue(IRubyObject value) {
40
-
41
- _result = value;
42
- }
43
-
44
- @Override
45
- public IRubyObject hashStart() {
46
- return RubyHash.newHash(_ruby);
47
- }
48
-
49
- @Override
50
- public void hashEnd() {
51
-
52
- }
53
-
54
- @Override
55
- public IRubyObject hashKey(String key) {
56
- return _keyConv.convert(_ruby, key);
57
- }
58
-
59
- @Override
60
- public void hashSet(RubyHash hash, IRubyObject key, IRubyObject value) {
61
- hash.fastASet(key, value);
62
- }
63
-
64
- @Override
65
- public IRubyObject arrayStart() {
66
- return RubyArray.newArray(_ruby);
67
- }
68
-
69
- @Override
70
- public void arrayEnd() {
71
-
72
- }
73
-
74
- @Override
75
- public void arrayAppend(RubyArray array, IRubyObject value) {
76
- array.append(value);
77
- }
78
-
79
- @Override
80
- public IRubyObject treatNull() {
81
- return _ctx.nil;
82
- }
83
-
84
- @Override
85
- public IRubyObject treatInt(JsonParser jp) throws IOException {
86
- return _intConv.convert(_ruby, jp);
87
- }
88
-
89
- @Override
90
- public IRubyObject treatFloat(JsonParser jp) throws IOException {
91
- return _floatConv.convert(_ruby, jp);
92
- }
93
-
94
- @Override
95
- public IRubyObject treatString(JsonParser jp) throws IOException {
96
- return _strConv.convert(_ruby, jp);
97
- }
98
-
99
- @Override
100
- public IRubyObject trueValue() {
101
- return _ruby.newBoolean(true);
102
- }
103
-
104
- @Override
105
- public IRubyObject falseValue() {
106
- return _ruby.newBoolean(false);
107
- }
108
-
109
- @Override
110
- public IRubyObject getResult() {
111
- return _result == null ? _ctx.nil : _result;
112
- }
113
-
114
- @Override
115
- public void raiseError(String e) {
116
- throw ParseError.newParseError(_ruby, e);
117
- }
118
-
119
- }
@@ -1,18 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonParser;
4
- import java.io.IOException;
5
- import org.jruby.Ruby;
6
- import org.jruby.RubyObject;
7
-
8
- /**
9
- *
10
- * @author Guy Boertje
11
- */
12
- public class RubyIntValueConverter implements RubyConverter {
13
-
14
- @Override
15
- public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
16
- return RubyUtils.rubyFixnum(ruby, jp.getLongValue());
17
- }
18
- }
@@ -1,80 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonFactory;
4
- import com.fasterxml.jackson.core.Version;
5
- import com.fasterxml.jackson.databind.DeserializationFeature;
6
- import com.fasterxml.jackson.databind.ObjectMapper;
7
- import com.fasterxml.jackson.databind.SerializationFeature;
8
- import com.fasterxml.jackson.databind.SerializationConfig;
9
- import com.fasterxml.jackson.databind.module.SimpleModule;
10
- import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
11
- import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
12
- import org.jruby.Ruby;
13
- import org.jruby.runtime.builtin.IRubyObject;
14
-
15
- import java.text.SimpleDateFormat;
16
- import java.util.TimeZone;
17
-
18
- public class RubyJacksonModule extends SimpleModule {
19
- public static final ObjectMapper static_mapper = new ObjectMapper();
20
- public static final JsonFactory factory = new JsonFactory(static_mapper).disable(JsonFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW);
21
- private static final TimeZone utcTimeZone = TimeZone.getTimeZone("UTC");
22
-
23
- private static final ThreadLocal<SimpleDateFormat> dateFormat = new ThreadLocal<SimpleDateFormat> () {
24
- @Override
25
- protected SimpleDateFormat initialValue() {
26
- SimpleDateFormat rdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
27
- rdf.setTimeZone(utcTimeZone);
28
- return rdf;
29
- }
30
- };
31
-
32
- static {
33
- static_mapper.registerModule(new RubyJacksonModule().addSerializer(
34
- IRubyObject.class, RubyAnySerializer.instance
35
- ));
36
- static_mapper.registerModule(new AfterburnerModule());
37
- static_mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
38
- }
39
-
40
- private RubyJacksonModule() {
41
- super("JrJacksonStrModule", new Version(1, 2, 28, "0", "com.jrjackson.jruby", "jrjackson"));
42
- }
43
-
44
- public static ObjectMapper mapperWith(Ruby ruby, RubyKeyConverter nameConverter,
45
- RubyConverter intConverter, RubyConverter floatConverter) {
46
-
47
- return static_mapper.copy().registerModule(
48
- new RubyJacksonModule().addDeserializer(
49
- Object.class,
50
- new RubyObjectDeserializer().with(ruby, nameConverter, intConverter, floatConverter)
51
- )
52
- );
53
- }
54
-
55
- public static ObjectMapper rawMapper() {
56
- return static_mapper;
57
- }
58
-
59
- public static DefaultSerializerProvider createProvider(SimpleDateFormat sdf) {
60
- // Use a copy of the SerializationConfig to avoid calling setDateFormat on the static ObjectMapper
61
- // object, removing its thread safety properties. In future, we might want to think about doing
62
- // a refactor to use ObjectWriters instead of modifying serialization configs.
63
- SerializationConfig config = static_mapper.getSerializationConfig().with(sdf);
64
- return ((DefaultSerializerProvider) static_mapper.getSerializerProvider()).createInstance(
65
- config,
66
- static_mapper.getSerializerFactory()
67
- );
68
- }
69
-
70
- public static DefaultSerializerProvider createProvider() {
71
- return createProvider(dateFormat.get());
72
- }
73
-
74
- public static ObjectMapper rawBigNumberMapper() {
75
- static_mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
76
- static_mapper.enable(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS);
77
- return static_mapper;
78
- }
79
-
80
- }
@@ -1,12 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.*;
4
-
5
- import java.io.IOException;
6
- import org.jruby.Ruby;
7
- import org.jruby.RubyObject;
8
-
9
- public interface RubyKeyConverter {
10
-
11
- public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException;
12
- }
@@ -1,9 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import org.jruby.Ruby;
4
- import org.jruby.RubyObject;
5
-
6
- public interface RubyNameConverter {
7
-
8
- public RubyObject convert(Ruby ruby, String name);
9
- }