jrjackson 0.3.9-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.__jrubyrc +433 -0
  3. data/.gitignore +10 -0
  4. data/.mvn/extensions.xml +8 -0
  5. data/Gemfile +10 -0
  6. data/Mavenfile +32 -0
  7. data/README.md +150 -0
  8. data/Rakefile +10 -0
  9. data/alt_bench.rb +46 -0
  10. data/changelog.md +131 -0
  11. data/jrjackson.gemspec +32 -0
  12. data/lib/com/fasterxml/jackson/core/jackson-annotations/2.7.1/jackson-annotations-2.7.1.jar +0 -0
  13. data/lib/com/fasterxml/jackson/core/jackson-core/2.7.1/jackson-core-2.7.1.jar +0 -0
  14. data/lib/com/fasterxml/jackson/core/jackson-databind/2.7.1/jackson-databind-2.7.1.jar +0 -0
  15. data/lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.6.3/jackson-module-afterburner-2.6.3.jar +0 -0
  16. data/lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.7.1/jackson-module-afterburner-2.7.1.jar +0 -0
  17. data/lib/jrjackson.rb +2 -0
  18. data/lib/jrjackson/build_info.rb +15 -0
  19. data/lib/jrjackson/jars/jrjackson-1.2.18.jar +0 -0
  20. data/lib/jrjackson/jars/jrjackson-1.2.7.jar +0 -0
  21. data/lib/jrjackson/jrjackson.rb +94 -0
  22. data/lib/jrjackson_jars.rb +7 -0
  23. data/lib/require_relative_patch.rb +6 -0
  24. data/pom.xml +193 -0
  25. data/profiling/profiled.rb +15 -0
  26. data/run_all_individual_bench.sh +25 -0
  27. data/run_jruby_individual_bench.sh +20 -0
  28. data/run_mri_individual_bench.sh +7 -0
  29. data/src/main/java/com/jrjackson/IParseHandler.java +53 -0
  30. data/src/main/java/com/jrjackson/JavaBigDecimalValueConverter.java +17 -0
  31. data/src/main/java/com/jrjackson/JavaBigIntValueConverter.java +17 -0
  32. data/src/main/java/com/jrjackson/JavaConverter.java +10 -0
  33. data/src/main/java/com/jrjackson/JavaFloatValueConverter.java +16 -0
  34. data/src/main/java/com/jrjackson/JavaHandler.java +118 -0
  35. data/src/main/java/com/jrjackson/JavaLongValueConverter.java +16 -0
  36. data/src/main/java/com/jrjackson/JjParse.java +147 -0
  37. data/src/main/java/com/jrjackson/JrJacksonBase.java +152 -0
  38. data/src/main/java/com/jrjackson/JrJacksonJava.java +81 -0
  39. data/src/main/java/com/jrjackson/JrJacksonRaw.java +108 -0
  40. data/src/main/java/com/jrjackson/JrJacksonRuby.java +89 -0
  41. data/src/main/java/com/jrjackson/JrJacksonSaj.java +26 -0
  42. data/src/main/java/com/jrjackson/JrJacksonSch.java +25 -0
  43. data/src/main/java/com/jrjackson/JrJacksonService.java +38 -0
  44. data/src/main/java/com/jrjackson/JrParse.java +149 -0
  45. data/src/main/java/com/jrjackson/ParseError.java +16 -0
  46. data/src/main/java/com/jrjackson/RubyAnySerializer.java +254 -0
  47. data/src/main/java/com/jrjackson/RubyBigDecimalValueConverter.java +18 -0
  48. data/src/main/java/com/jrjackson/RubyBigIntValueConverter.java +21 -0
  49. data/src/main/java/com/jrjackson/RubyConverter.java +12 -0
  50. data/src/main/java/com/jrjackson/RubyDateFormat.java +34 -0
  51. data/src/main/java/com/jrjackson/RubyFloatValueConverter.java +18 -0
  52. data/src/main/java/com/jrjackson/RubyHandler.java +119 -0
  53. data/src/main/java/com/jrjackson/RubyIntValueConverter.java +18 -0
  54. data/src/main/java/com/jrjackson/RubyJacksonModule.java +72 -0
  55. data/src/main/java/com/jrjackson/RubyKeyConverter.java +12 -0
  56. data/src/main/java/com/jrjackson/RubyNameConverter.java +9 -0
  57. data/src/main/java/com/jrjackson/RubyObjectDeserializer.java +182 -0
  58. data/src/main/java/com/jrjackson/RubyStringConverter.java +18 -0
  59. data/src/main/java/com/jrjackson/RubyStringKeyConverter.java +15 -0
  60. data/src/main/java/com/jrjackson/RubyStringNameConverter.java +12 -0
  61. data/src/main/java/com/jrjackson/RubySymbolKeyConverter.java +15 -0
  62. data/src/main/java/com/jrjackson/RubySymbolNameConverter.java +12 -0
  63. data/src/main/java/com/jrjackson/RubyUtils.java +150 -0
  64. data/src/main/java/com/jrjackson/SajParse.java +169 -0
  65. data/src/main/java/com/jrjackson/SchParse.java +209 -0
  66. data/src/main/java/com/jrjackson/StreamParse.java +66 -0
  67. data/test/jrjackson_test.rb +533 -0
  68. metadata +162 -0
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,72 @@
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.ObjectMapper;
6
+ import com.fasterxml.jackson.databind.module.SimpleModule;
7
+ import com.fasterxml.jackson.databind.SerializationFeature;
8
+ import com.fasterxml.jackson.databind.DeserializationFeature;
9
+ import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;
10
+ import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
11
+ import java.text.SimpleDateFormat;
12
+
13
+ import org.jruby.Ruby;
14
+ import org.jruby.runtime.builtin.IRubyObject;
15
+
16
+ public class RubyJacksonModule extends SimpleModule {
17
+
18
+ private static final SimpleDateFormat RDF = new RubyDateFormat("yyyy-MM-dd HH:mm:ss Z");
19
+
20
+ private static final ObjectMapper static_mapper = new ObjectMapper();
21
+ public static final JsonFactory factory = new JsonFactory(static_mapper).disable(JsonFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW);
22
+
23
+ static {
24
+ static_mapper.registerModule(new RubyJacksonModule().addSerializer(
25
+ IRubyObject.class, RubyAnySerializer.instance
26
+ ));
27
+ static_mapper.registerModule(new AfterburnerModule());
28
+ static_mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
29
+ }
30
+
31
+ private RubyJacksonModule() {
32
+ super("JrJacksonStrModule", new Version(1, 2, 18, "0", "com.jrjackson.jruby", "jrjackson"));
33
+ }
34
+
35
+ public static ObjectMapper mapperWith(Ruby ruby, RubyKeyConverter nameConverter,
36
+ RubyConverter intConverter, RubyConverter floatConverter) {
37
+
38
+ return static_mapper.copy().registerModule(
39
+ new RubyJacksonModule().addDeserializer(
40
+ Object.class,
41
+ new RubyObjectDeserializer().with(ruby, nameConverter, intConverter, floatConverter)
42
+ )
43
+ );
44
+ }
45
+
46
+ public static ObjectMapper rawMapper() {
47
+ return static_mapper;
48
+ }
49
+
50
+ public static DefaultSerializerProvider createProvider(SimpleDateFormat sdf) {
51
+ static_mapper.setDateFormat(sdf);
52
+ return ((DefaultSerializerProvider) static_mapper.getSerializerProvider()).createInstance(
53
+ static_mapper.getSerializationConfig(),
54
+ static_mapper.getSerializerFactory()
55
+ );
56
+ }
57
+
58
+ public static DefaultSerializerProvider createProvider() {
59
+ static_mapper.setDateFormat(RDF);
60
+ return ((DefaultSerializerProvider) static_mapper.getSerializerProvider()).createInstance(
61
+ static_mapper.getSerializationConfig(),
62
+ static_mapper.getSerializerFactory()
63
+ );
64
+ }
65
+
66
+ public static ObjectMapper rawBigNumberMapper() {
67
+ static_mapper.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
68
+ static_mapper.enable(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS);
69
+ return static_mapper;
70
+ }
71
+
72
+ }
@@ -0,0 +1,12 @@
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
+ }
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,182 @@
1
+ package com.jrjackson;
2
+
3
+ import java.io.IOException;
4
+
5
+ import com.fasterxml.jackson.core.*;
6
+
7
+ import com.fasterxml.jackson.databind.DeserializationContext;
8
+ import com.fasterxml.jackson.databind.util.ObjectBuffer;
9
+ import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
10
+
11
+ import org.jruby.Ruby;
12
+ import org.jruby.RubyObject;
13
+ import org.jruby.RubyArray;
14
+ import org.jruby.RubyHash;
15
+
16
+
17
+ public class RubyObjectDeserializer
18
+ extends StdDeserializer<RubyObject> {
19
+
20
+ private static final long serialVersionUID = 1L;
21
+
22
+ private Ruby _ruby;
23
+
24
+ private RubyKeyConverter _key_converter;
25
+ private RubyConverter _int_converter;
26
+ private RubyConverter _float_converter;
27
+ final private RubyStringConverter _str_converter = new RubyStringConverter();
28
+
29
+ public RubyObjectDeserializer() {
30
+ super(RubyObject.class);
31
+ }
32
+
33
+ public RubyObjectDeserializer with(Ruby ruby, RubyKeyConverter nameConv,
34
+ RubyConverter intConv, RubyConverter floatConv) {
35
+ _ruby = ruby;
36
+ _key_converter = nameConv;
37
+ _int_converter = intConv;
38
+ _float_converter = floatConv;
39
+ return this;
40
+ }
41
+
42
+ /**
43
+ * /**********************************************************
44
+ * /* Deserializer API /**********************************************************
45
+ * @param jp
46
+ * @param ctxt
47
+ * @return
48
+ * @throws java.io.IOException
49
+ * @throws com.fasterxml.jackson.core.JsonProcessingException
50
+ */
51
+
52
+ @Override
53
+ public RubyObject deserialize(JsonParser jp, DeserializationContext ctxt)
54
+ throws IOException, JsonProcessingException {
55
+
56
+ switch (jp.getCurrentToken()) {
57
+ case START_OBJECT:
58
+ return mapObject(jp, ctxt);
59
+
60
+ case START_ARRAY:
61
+ return mapArray(jp, ctxt);
62
+
63
+ case FIELD_NAME:
64
+ return _key_converter.convert(_ruby, jp);
65
+
66
+ case VALUE_EMBEDDED_OBJECT:
67
+ return RubyUtils.rubyObject(_ruby, jp.getEmbeddedObject());
68
+
69
+ case VALUE_STRING:
70
+ return _str_converter.convert(_ruby, jp);
71
+
72
+ case VALUE_NUMBER_INT:
73
+ /* [JACKSON-100]: caller may want to get all integral values
74
+ * returned as BigInteger, for consistency
75
+ */
76
+ return _int_converter.convert(_ruby, jp);
77
+
78
+ case VALUE_NUMBER_FLOAT:
79
+ return _float_converter.convert(_ruby, jp);
80
+
81
+ case VALUE_TRUE:
82
+ return _ruby.newBoolean(Boolean.TRUE);
83
+
84
+ case VALUE_FALSE:
85
+ return _ruby.newBoolean(Boolean.FALSE);
86
+
87
+ case VALUE_NULL: // should not get this but...
88
+ return (RubyObject) _ruby.getNil();
89
+
90
+ case END_ARRAY: // invalid
91
+ case END_OBJECT: // invalid
92
+ default:
93
+ throw ctxt.mappingException(Object.class);
94
+ }
95
+ }
96
+
97
+ /**
98
+ * /**********************************************************
99
+ * /* Internal methods /**********************************************************
100
+ */
101
+ /**
102
+ * Method called to map a JSON Array into a Java value.
103
+ * @param jp
104
+ * @param ctxt
105
+ * @return RubyObject
106
+ * @throws java.io.IOException
107
+ * @throws com.fasterxml.jackson.core.JsonProcessingException
108
+ */
109
+ protected RubyObject mapArray(JsonParser jp, DeserializationContext ctxt)
110
+ throws IOException, JsonProcessingException {
111
+ // if (ctxt.isEnabled(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)) {
112
+ // return mapArrayToArray(jp, ctxt);
113
+ // }
114
+ // Minor optimization to handle small lists (default size for ArrayList is 10)
115
+ if (jp.nextToken() == JsonToken.END_ARRAY) {
116
+ return RubyArray.newArray(_ruby);
117
+ }
118
+ ObjectBuffer buffer = ctxt.leaseObjectBuffer();
119
+ Object[] values = buffer.resetAndStart();
120
+ int ptr = 0;
121
+ long totalSize = 0;
122
+ do {
123
+ Object value = deserialize(jp, ctxt);
124
+ ++totalSize;
125
+ if (ptr >= values.length) {
126
+ values = buffer.appendCompletedChunk(values);
127
+ ptr = 0;
128
+ }
129
+ values[ptr++] = value;
130
+ } while (jp.nextToken() != JsonToken.END_ARRAY);
131
+ // let's create almost full array, with 1/8 slack
132
+ RubyArray result = RubyArray.newArray(_ruby, (totalSize + (totalSize >> 3) + 1));
133
+ buffer.completeAndClearBuffer(values, ptr, result);
134
+ return result;
135
+ }
136
+
137
+ /**
138
+ * Method called to map a JSON Object into a Java value.
139
+ * @param jp
140
+ * @param ctxt
141
+ * @return RubyObject
142
+ * @throws java.io.IOException
143
+ * @throws com.fasterxml.jackson.core.JsonProcessingException
144
+ */
145
+ protected RubyObject mapObject(JsonParser jp, DeserializationContext ctxt)
146
+ throws IOException, JsonProcessingException {
147
+ JsonToken t = jp.getCurrentToken();
148
+ if (t == JsonToken.START_OBJECT) {
149
+ t = jp.nextToken();
150
+ }
151
+ // 1.6: minor optimization; let's handle 1 and 2 entry cases separately
152
+ if (t != JsonToken.FIELD_NAME) { // and empty one too
153
+ // empty map might work; but caller may want to modify... so better just give small modifiable
154
+ return RubyHash.newHash(_ruby);
155
+ }
156
+
157
+ RubyObject field1 = _key_converter.convert(_ruby, jp);
158
+ jp.nextToken();
159
+ RubyObject value1 = deserialize(jp, ctxt);
160
+
161
+ if (jp.nextToken() != JsonToken.FIELD_NAME) { // single entry; but we want modifiable
162
+ return RubyUtils.rubyHash(_ruby, field1, value1);
163
+ }
164
+
165
+ RubyObject field2 = _key_converter.convert(_ruby, jp);
166
+ jp.nextToken();
167
+
168
+ RubyHash result = RubyUtils.rubyHash(_ruby, field1, value1, field2, deserialize(jp, ctxt));
169
+
170
+ if (jp.nextToken() != JsonToken.FIELD_NAME) {
171
+ return result;
172
+ }
173
+
174
+ // And then the general case; default map size is 16
175
+ do {
176
+ RubyObject fieldName = _key_converter.convert(_ruby, jp);
177
+ jp.nextToken();
178
+ result.fastASetCheckString(_ruby, fieldName, deserialize(jp, ctxt));
179
+ } while (jp.nextToken() != JsonToken.END_OBJECT);
180
+ return result;
181
+ }
182
+ }
@@ -0,0 +1,18 @@
1
+ package com.jrjackson;
2
+
3
+ import com.fasterxml.jackson.core.*;
4
+
5
+ import java.io.IOException;
6
+ import java.nio.CharBuffer;
7
+ import org.jruby.Ruby;
8
+ import org.jruby.RubyObject;
9
+
10
+ public class RubyStringConverter implements RubyConverter {
11
+
12
+ @Override
13
+ public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
14
+ return RubyUtils.rubyString(ruby,
15
+ CharBuffer.wrap(jp.getTextCharacters(), 0, jp.getTextLength())
16
+ );
17
+ }
18
+ }
@@ -0,0 +1,15 @@
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 class RubyStringKeyConverter implements RubyKeyConverter {
10
+
11
+ @Override
12
+ public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
13
+ return RubyUtils.rubyString(ruby, jp.getCurrentName());
14
+ }
15
+ }
@@ -0,0 +1,12 @@
1
+ package com.jrjackson;
2
+
3
+ import org.jruby.Ruby;
4
+ import org.jruby.RubyObject;
5
+
6
+ public class RubyStringNameConverter implements RubyNameConverter {
7
+
8
+ @Override
9
+ public RubyObject convert(Ruby ruby, String name){
10
+ return RubyUtils.rubyString(ruby, name);
11
+ }
12
+ }
@@ -0,0 +1,15 @@
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 class RubySymbolKeyConverter implements RubyKeyConverter {
10
+
11
+ @Override
12
+ public RubyObject convert(Ruby ruby, JsonParser jp) throws IOException {
13
+ return RubyUtils.rubySymbol(ruby, jp.getCurrentName());
14
+ }
15
+ }
@@ -0,0 +1,12 @@
1
+ package com.jrjackson;
2
+
3
+ import org.jruby.Ruby;
4
+ import org.jruby.RubyObject;
5
+
6
+ public class RubySymbolNameConverter implements RubyNameConverter {
7
+
8
+ @Override
9
+ public RubyObject convert(Ruby ruby, String s) {
10
+ return RubyUtils.rubySymbol(ruby, s);
11
+ }
12
+ }
@@ -0,0 +1,150 @@
1
+ package com.jrjackson;
2
+
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
+ import org.joda.time.DateTime;
11
+ import org.joda.time.DateTimeZone;
12
+ import org.joda.time.format.DateTimeFormat;
13
+ 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;
26
+ import org.jruby.ext.bigdecimal.RubyBigDecimal;
27
+ import org.jruby.runtime.builtin.IRubyObject;
28
+ import org.jruby.util.ByteList;
29
+ import org.jruby.util.SafeDoubleParser;
30
+
31
+ public class RubyUtils {
32
+
33
+ private final static DateTimeFormatter FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z").withLocale(Locale.ENGLISH);
34
+ private final static DateTimeFormatter UTC_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss 'UTC'").withLocale(Locale.ENGLISH);
35
+
36
+ public static RubyObject rubyObject(Ruby ruby, Object node) {
37
+ return (RubyObject) JavaUtil.convertJavaToRuby(ruby, node);
38
+ }
39
+
40
+ public static RubyString rubyString(Ruby ruby, String node) {
41
+ return RubyString.newUnicodeString(ruby, node);
42
+ }
43
+
44
+ public static RubyString rubyString(Ruby ruby, byte[] node) {
45
+ return RubyString.newString(ruby, node);
46
+ }
47
+
48
+ public static RubyString rubyString(Ruby ruby, CharSequence node) {
49
+ return RubyString.newUnicodeString(ruby, node);
50
+ }
51
+
52
+ public static RubySymbol rubySymbol(Ruby ruby, String node) {
53
+ return RubySymbol.newSymbol(ruby, node);
54
+ }
55
+
56
+ public static RubyArray rubyArray(Ruby ruby, Object[] arg) {
57
+ return (RubyArray) JavaUtil.convertJavaToRuby(ruby, arg);
58
+ }
59
+
60
+ public static RubyArray rubyArray(Ruby ruby, List arg) {
61
+ return (RubyArray) JavaUtil.convertJavaToRuby(ruby, arg);
62
+ }
63
+
64
+ public static RubyHash rubyHash(Ruby ruby, Map arg) {
65
+ return (RubyHash) JavaUtil.convertJavaToRuby(ruby, arg);
66
+ }
67
+
68
+ public static RubyFixnum rubyFixnum(Ruby ruby, int arg) {
69
+ return ruby.newFixnum(arg);
70
+ }
71
+
72
+ public static RubyFixnum rubyFixnum(Ruby ruby, long arg) {
73
+ return ruby.newFixnum(arg);
74
+ }
75
+
76
+ public static RubyBignum rubyBignum(Ruby ruby, BigInteger arg) {
77
+ return RubyBignum.newBignum(ruby, arg);
78
+ }
79
+
80
+ public static RubyFloat rubyFloat(Ruby ruby, double arg) {
81
+ return ruby.newFloat(arg);
82
+ }
83
+
84
+ public static RubyFloat rubyFloat(Ruby ruby, String arg) {
85
+ double d = SafeDoubleParser.parseDouble(arg);
86
+ return ruby.newFloat(d);
87
+ }
88
+
89
+ public static RubyBigDecimal rubyBigDecimal(Ruby ruby, BigDecimal arg) {
90
+ return new RubyBigDecimal(ruby, arg);
91
+ }
92
+
93
+ public static RubyBoolean rubyBoolean(Ruby ruby, Boolean arg) {
94
+ return ruby.newBoolean(arg);
95
+ }
96
+
97
+ public static RubyHash rubyHash(Ruby ruby, IRubyObject key, IRubyObject value) {
98
+ RubyHash hash = RubyHash.newHash(ruby);
99
+ hash.fastASet(key, value);
100
+ return hash;
101
+ }
102
+
103
+ public static RubyHash rubyHash(Ruby ruby, IRubyObject key1, IRubyObject value1,
104
+ IRubyObject key2, IRubyObject value2) {
105
+ RubyHash hash = rubyHash(ruby, key1, value1);
106
+ hash.fastASet(key2, value2);
107
+ return hash;
108
+ }
109
+
110
+ public static String jodaTimeString(DateTime dt) {
111
+ // copied from the RubyTime to_s method
112
+ // to prevent the double handling of a String -> RubyString -> String
113
+ DateTimeFormatter simpleDateFormat;
114
+ if (dt.getZone() == DateTimeZone.UTC) {
115
+ simpleDateFormat = UTC_FORMATTER;
116
+ } else {
117
+ simpleDateFormat = FORMATTER;
118
+ }
119
+
120
+ return simpleDateFormat.print(dt);
121
+
122
+ // JrJackson: no access to private boolean isTzRelative
123
+
124
+ // String result = simpleDateFormat.print(dt);
125
+ //
126
+ // if (isTzRelative) {
127
+ // // display format needs to invert the UTC offset if this object was
128
+ // // created with a specific offset in the 7-arg form of #new
129
+ // DateTimeZone dtz = dt.getZone();
130
+ // int offset = dtz.toTimeZone().getOffset(dt.getMillis());
131
+ // DateTimeZone invertedDTZ = DateTimeZone.forOffsetMillis(offset);
132
+ // DateTime invertedDT = dt.withZone(invertedDTZ);
133
+ // result = simpleDateFormat.print(invertedDT);
134
+ // }
135
+ //
136
+ // return result;
137
+ }
138
+
139
+
140
+ public static void writeBytes(IRubyObject value, JsonGenerator jgen)
141
+ throws IOException {
142
+ // jgen.writeString(value.toString());
143
+ // byte[] b = s.getBytes();
144
+ // jgen.writeUTF8String(b, 0, b.length);
145
+ // jgen.writeUTF8String(s.getBytes(), 0, s.size());
146
+ RubyString s = (RubyString)value;
147
+ ByteList b = s.getByteList();
148
+ jgen.writeUTF8String(b.unsafeBytes(), b.begin(), b.length());
149
+ }
150
+ }