jrjackson 0.4.18-java → 0.4.19-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/jrjackson.gemspec +1 -2
- 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
- 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
- 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
- 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
- data/lib/jrjackson/build_info.rb +8 -8
- data/lib/jrjackson/jars/{jrjackson-1.2.35.jar → jrjackson-1.2.36.jar} +0 -0
- data/lib/jrjackson_jars.rb +8 -8
- data/pom.xml +47 -10
- metadata +13 -78
- data/.gitignore +0 -16
- data/.jrubyr_c +0 -433
- data/Gemfile +0 -13
- data/Mavenfile +0 -25
- data/Rakefile +0 -39
- data/alt_bench.rb +0 -46
- data/changelog.md +0 -181
- data/profiling/profiled.rb +0 -15
- data/run_all_individual_bench.sh +0 -25
- data/run_jruby_individual_bench.sh +0 -20
- data/run_mri_individual_bench.sh +0 -7
- data/src/main/java/com/jrjackson/IParseHandler.java +0 -53
- data/src/main/java/com/jrjackson/JavaBigDecimalValueConverter.java +0 -17
- data/src/main/java/com/jrjackson/JavaBigIntValueConverter.java +0 -17
- data/src/main/java/com/jrjackson/JavaConverter.java +0 -10
- data/src/main/java/com/jrjackson/JavaFloatValueConverter.java +0 -16
- data/src/main/java/com/jrjackson/JavaHandler.java +0 -118
- data/src/main/java/com/jrjackson/JavaLongValueConverter.java +0 -16
- data/src/main/java/com/jrjackson/JjParse.java +0 -139
- data/src/main/java/com/jrjackson/JrJacksonBase.java +0 -152
- data/src/main/java/com/jrjackson/JrJacksonJava.java +0 -81
- data/src/main/java/com/jrjackson/JrJacksonRaw.java +0 -108
- data/src/main/java/com/jrjackson/JrJacksonRuby.java +0 -89
- data/src/main/java/com/jrjackson/JrJacksonSaj.java +0 -26
- data/src/main/java/com/jrjackson/JrJacksonSch.java +0 -25
- data/src/main/java/com/jrjackson/JrJacksonService.java +0 -38
- data/src/main/java/com/jrjackson/JrParse.java +0 -142
- data/src/main/java/com/jrjackson/ParseError.java +0 -16
- data/src/main/java/com/jrjackson/RubyAnySerializer.java +0 -291
- data/src/main/java/com/jrjackson/RubyBigDecimalValueConverter.java +0 -18
- data/src/main/java/com/jrjackson/RubyBigIntValueConverter.java +0 -21
- data/src/main/java/com/jrjackson/RubyConverter.java +0 -12
- data/src/main/java/com/jrjackson/RubyDateFormat.java +0 -34
- data/src/main/java/com/jrjackson/RubyFloatValueConverter.java +0 -18
- data/src/main/java/com/jrjackson/RubyHandler.java +0 -119
- data/src/main/java/com/jrjackson/RubyIntValueConverter.java +0 -18
- data/src/main/java/com/jrjackson/RubyJacksonModule.java +0 -80
- data/src/main/java/com/jrjackson/RubyKeyConverter.java +0 -12
- data/src/main/java/com/jrjackson/RubyNameConverter.java +0 -9
- data/src/main/java/com/jrjackson/RubyObjectDeserializer.java +0 -182
- data/src/main/java/com/jrjackson/RubyStringConverter.java +0 -18
- data/src/main/java/com/jrjackson/RubyStringKeyConverter.java +0 -15
- data/src/main/java/com/jrjackson/RubyStringNameConverter.java +0 -12
- data/src/main/java/com/jrjackson/RubySymbolKeyConverter.java +0 -15
- data/src/main/java/com/jrjackson/RubySymbolNameConverter.java +0 -12
- data/src/main/java/com/jrjackson/RubyUtils.java +0 -149
- data/src/main/java/com/jrjackson/SajParse.java +0 -169
- data/src/main/java/com/jrjackson/SchParse.java +0 -209
- data/src/main/java/com/jrjackson/StreamParse.java +0 -66
- data/src/test/java/com/jrjackson/RubyAnySerializerTest.java +0 -56
- data/test/jrjackson_test.rb +0 -578
@@ -1,182 +0,0 @@
|
|
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
|
-
}
|
@@ -1,18 +0,0 @@
|
|
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
|
-
}
|
@@ -1,15 +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 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
|
-
}
|
@@ -1,12 +0,0 @@
|
|
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
|
-
}
|
@@ -1,15 +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 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
|
-
}
|
@@ -1,12 +0,0 @@
|
|
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
|
-
}
|
@@ -1,149 +0,0 @@
|
|
1
|
-
package com.jrjackson;
|
2
|
-
|
3
|
-
import com.fasterxml.jackson.core.JsonGenerator;
|
4
|
-
import org.joda.time.DateTime;
|
5
|
-
import org.joda.time.DateTimeZone;
|
6
|
-
import org.joda.time.format.DateTimeFormat;
|
7
|
-
import org.joda.time.format.DateTimeFormatter;
|
8
|
-
import org.jruby.*;
|
9
|
-
import org.jruby.ext.bigdecimal.RubyBigDecimal;
|
10
|
-
import org.jruby.javasupport.JavaUtil;
|
11
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
12
|
-
import org.jruby.util.ByteList;
|
13
|
-
import org.jruby.util.SafeDoubleParser;
|
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
|
-
|
22
|
-
public class RubyUtils {
|
23
|
-
|
24
|
-
private final static DateTimeFormatter FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss Z").withLocale(Locale.ENGLISH);
|
25
|
-
private final static DateTimeFormatter UTC_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss 'UTC'").withLocale(Locale.ENGLISH);
|
26
|
-
|
27
|
-
public static RubyObject rubyObject(Ruby ruby, Object node) {
|
28
|
-
return (RubyObject) JavaUtil.convertJavaToRuby(ruby, node);
|
29
|
-
}
|
30
|
-
|
31
|
-
public static RubyString rubyString(Ruby ruby, String node) {
|
32
|
-
return RubyString.newUnicodeString(ruby, node);
|
33
|
-
}
|
34
|
-
|
35
|
-
public static RubyString rubyString(Ruby ruby, byte[] node) {
|
36
|
-
return RubyString.newString(ruby, node);
|
37
|
-
}
|
38
|
-
|
39
|
-
public static RubyString rubyString(Ruby ruby, CharSequence node) {
|
40
|
-
return RubyString.newUnicodeString(ruby, node);
|
41
|
-
}
|
42
|
-
|
43
|
-
public static RubySymbol rubySymbol(Ruby ruby, String node) {
|
44
|
-
return RubySymbol.newSymbol(ruby, node);
|
45
|
-
}
|
46
|
-
|
47
|
-
public static RubyArray rubyArray(Ruby ruby, Object[] arg) {
|
48
|
-
return (RubyArray) JavaUtil.convertJavaToRuby(ruby, arg);
|
49
|
-
}
|
50
|
-
|
51
|
-
public static RubyArray rubyArray(Ruby ruby, List arg) {
|
52
|
-
return (RubyArray) JavaUtil.convertJavaToRuby(ruby, arg);
|
53
|
-
}
|
54
|
-
|
55
|
-
public static RubyHash rubyHash(Ruby ruby, Map arg) {
|
56
|
-
return (RubyHash) JavaUtil.convertJavaToRuby(ruby, arg);
|
57
|
-
}
|
58
|
-
|
59
|
-
public static RubyFixnum rubyFixnum(Ruby ruby, int arg) {
|
60
|
-
return ruby.newFixnum(arg);
|
61
|
-
}
|
62
|
-
|
63
|
-
public static RubyFixnum rubyFixnum(Ruby ruby, long arg) {
|
64
|
-
return ruby.newFixnum(arg);
|
65
|
-
}
|
66
|
-
|
67
|
-
public static RubyBignum rubyBignum(Ruby ruby, BigInteger arg) {
|
68
|
-
return RubyBignum.newBignum(ruby, arg);
|
69
|
-
}
|
70
|
-
|
71
|
-
public static RubyFloat rubyFloat(Ruby ruby, double arg) {
|
72
|
-
return ruby.newFloat(arg);
|
73
|
-
}
|
74
|
-
|
75
|
-
public static RubyFloat rubyFloat(Ruby ruby, String arg) {
|
76
|
-
double d = SafeDoubleParser.parseDouble(arg);
|
77
|
-
return ruby.newFloat(d);
|
78
|
-
}
|
79
|
-
|
80
|
-
public static RubyBigDecimal rubyBigDecimal(Ruby ruby, BigDecimal arg) {
|
81
|
-
return new RubyBigDecimal(ruby, arg);
|
82
|
-
}
|
83
|
-
|
84
|
-
public static RubyBoolean rubyBoolean(Ruby ruby, Boolean arg) {
|
85
|
-
return ruby.newBoolean(arg);
|
86
|
-
}
|
87
|
-
|
88
|
-
public static RubyHash rubyHash(Ruby ruby, IRubyObject key, IRubyObject value) {
|
89
|
-
RubyHash hash = RubyHash.newHash(ruby);
|
90
|
-
hash.fastASet(key, value);
|
91
|
-
return hash;
|
92
|
-
}
|
93
|
-
|
94
|
-
public static RubyHash rubyHash(Ruby ruby, IRubyObject key1, IRubyObject value1,
|
95
|
-
IRubyObject key2, IRubyObject value2) {
|
96
|
-
RubyHash hash = rubyHash(ruby, key1, value1);
|
97
|
-
hash.fastASet(key2, value2);
|
98
|
-
return hash;
|
99
|
-
}
|
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
|
-
|
109
|
-
public static String jodaTimeString(DateTime dt) {
|
110
|
-
// copied from the RubyTime to_s method
|
111
|
-
// to prevent the double handling of a String -> RubyString -> String
|
112
|
-
DateTimeFormatter simpleDateFormat;
|
113
|
-
if (dt.getZone() == DateTimeZone.UTC) {
|
114
|
-
simpleDateFormat = UTC_FORMATTER;
|
115
|
-
} else {
|
116
|
-
simpleDateFormat = FORMATTER;
|
117
|
-
}
|
118
|
-
|
119
|
-
return simpleDateFormat.print(dt);
|
120
|
-
|
121
|
-
// JrJackson: no access to private boolean isTzRelative
|
122
|
-
|
123
|
-
// String result = simpleDateFormat.print(dt);
|
124
|
-
//
|
125
|
-
// if (isTzRelative) {
|
126
|
-
// // display format needs to invert the UTC offset if this object was
|
127
|
-
// // created with a specific offset in the 7-arg form of #new
|
128
|
-
// DateTimeZone dtz = dt.getZone();
|
129
|
-
// int offset = dtz.toTimeZone().getOffset(dt.getMillis());
|
130
|
-
// DateTimeZone invertedDTZ = DateTimeZone.forOffsetMillis(offset);
|
131
|
-
// DateTime invertedDT = dt.withZone(invertedDTZ);
|
132
|
-
// result = simpleDateFormat.print(invertedDT);
|
133
|
-
// }
|
134
|
-
//
|
135
|
-
// return result;
|
136
|
-
}
|
137
|
-
|
138
|
-
|
139
|
-
public static void writeBytes(IRubyObject value, JsonGenerator jgen)
|
140
|
-
throws IOException {
|
141
|
-
// jgen.writeString(value.toString());
|
142
|
-
// byte[] b = s.getBytes();
|
143
|
-
// jgen.writeUTF8String(b, 0, b.length);
|
144
|
-
// jgen.writeUTF8String(s.getBytes(), 0, s.size());
|
145
|
-
RubyString s = (RubyString)value;
|
146
|
-
ByteList b = s.getByteList();
|
147
|
-
jgen.writeUTF8String(b.unsafeBytes(), b.begin(), b.length());
|
148
|
-
}
|
149
|
-
}
|
@@ -1,169 +0,0 @@
|
|
1
|
-
package com.jrjackson;
|
2
|
-
|
3
|
-
import com.fasterxml.jackson.core.JsonParser;
|
4
|
-
import com.fasterxml.jackson.core.JsonProcessingException;
|
5
|
-
import com.fasterxml.jackson.core.JsonStreamContext;
|
6
|
-
import com.fasterxml.jackson.core.JsonLocation;
|
7
|
-
|
8
|
-
import java.io.IOException;
|
9
|
-
|
10
|
-
import org.jruby.internal.runtime.methods.DynamicMethod;
|
11
|
-
import org.jruby.runtime.ThreadContext;
|
12
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
13
|
-
import org.jruby.exceptions.RaiseException;
|
14
|
-
|
15
|
-
/**
|
16
|
-
*
|
17
|
-
* @author Guy Boertje
|
18
|
-
*/
|
19
|
-
public class SajParse extends StreamParse {
|
20
|
-
|
21
|
-
protected DynamicMethod _error;
|
22
|
-
protected boolean _no_error;
|
23
|
-
|
24
|
-
public SajParse(ThreadContext ctx, IRubyObject handler)
|
25
|
-
throws RaiseException {
|
26
|
-
super(ctx, handler);
|
27
|
-
|
28
|
-
if (_no_add_value) {
|
29
|
-
throw ParseError.newParseError(_ruby, "Handler does not implement public API");
|
30
|
-
}
|
31
|
-
_error = _meta.searchMethod("error");
|
32
|
-
_no_error = _error.isUndefined();
|
33
|
-
|
34
|
-
}
|
35
|
-
|
36
|
-
@Override
|
37
|
-
public IRubyObject deserialize(JsonParser jp) {
|
38
|
-
|
39
|
-
try {
|
40
|
-
while(jp.nextValue() != null) {
|
41
|
-
handleCurrentToken(jp);
|
42
|
-
}
|
43
|
-
}
|
44
|
-
catch (JsonProcessingException e) {
|
45
|
-
if(!_no_error) {
|
46
|
-
JsonLocation location = e.getLocation();
|
47
|
-
IRubyObject message = RubyUtils.rubyString(_ruby, e.getMessage());
|
48
|
-
IRubyObject line = RubyUtils.rubyFixnum(_ruby, location.getLineNr());
|
49
|
-
IRubyObject column = RubyUtils.rubyFixnum(_ruby, location.getColumnNr());
|
50
|
-
|
51
|
-
_error.call(_ctx, _handler, _meta, "error", message, line, column);
|
52
|
-
}
|
53
|
-
}
|
54
|
-
catch (IOException e) {
|
55
|
-
if(!_no_error) {
|
56
|
-
IRubyObject message = RubyUtils.rubyString(_ruby, e.getMessage());
|
57
|
-
IRubyObject line = RubyUtils.rubyFixnum(_ruby, 1);
|
58
|
-
IRubyObject column = RubyUtils.rubyFixnum(_ruby, 1);
|
59
|
-
|
60
|
-
_error.call(_ctx, _handler, _meta, "error", message, line, column);
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
return _ctx.nil;
|
65
|
-
}
|
66
|
-
|
67
|
-
private void callAddValue(IRubyObject val, IRubyObject key) {
|
68
|
-
_add_value.call(_ctx, _handler, _meta, "add_value", val, key);
|
69
|
-
}
|
70
|
-
|
71
|
-
private IRubyObject getParentName(JsonStreamContext x) {
|
72
|
-
String parentName = x.getCurrentName();
|
73
|
-
IRubyObject parent = _ctx.nil;
|
74
|
-
|
75
|
-
if (!x.inRoot()) {
|
76
|
-
parentName = x.getParent().getCurrentName();
|
77
|
-
}
|
78
|
-
if (parentName != null) {
|
79
|
-
parent = RubyUtils.rubyString(_ruby, parentName);
|
80
|
-
}
|
81
|
-
return parent;
|
82
|
-
}
|
83
|
-
|
84
|
-
private IRubyObject getFieldName(JsonStreamContext x) {
|
85
|
-
String currentName = x.getCurrentName();
|
86
|
-
IRubyObject name = _ctx.nil;
|
87
|
-
|
88
|
-
if (currentName != null) {
|
89
|
-
name = RubyUtils.rubyString(_ruby, currentName);
|
90
|
-
}
|
91
|
-
return name;
|
92
|
-
}
|
93
|
-
|
94
|
-
private void handleCurrentToken(JsonParser jp)
|
95
|
-
throws IOException, JsonProcessingException {
|
96
|
-
|
97
|
-
JsonStreamContext cx = jp.getParsingContext();
|
98
|
-
|
99
|
-
IRubyObject value;
|
100
|
-
|
101
|
-
switch (jp.getCurrentToken()) {
|
102
|
-
case START_OBJECT:
|
103
|
-
if (!_no_hash_start) {
|
104
|
-
_hash_start.call(_ctx, _handler, _meta, "hash_start", getParentName(cx));
|
105
|
-
}
|
106
|
-
break;
|
107
|
-
|
108
|
-
case START_ARRAY:
|
109
|
-
if (!_no_array_start) {
|
110
|
-
_array_start.call(_ctx, _handler, _meta, "array_start", getParentName(cx));
|
111
|
-
}
|
112
|
-
break;
|
113
|
-
|
114
|
-
case FIELD_NAME:
|
115
|
-
break;
|
116
|
-
|
117
|
-
case VALUE_EMBEDDED_OBJECT:
|
118
|
-
value = RubyUtils.rubyObject(_ruby, jp.getEmbeddedObject());
|
119
|
-
callAddValue(value, getFieldName(cx));
|
120
|
-
break;
|
121
|
-
|
122
|
-
case VALUE_STRING:
|
123
|
-
value = keyConverter.convert(_ruby, jp);
|
124
|
-
callAddValue(value, getFieldName(cx));
|
125
|
-
break;
|
126
|
-
|
127
|
-
case VALUE_NUMBER_INT:
|
128
|
-
/* [JACKSON-100]: caller may want to get all integral values
|
129
|
-
* returned as BigInteger, for consistency
|
130
|
-
*/
|
131
|
-
JsonParser.NumberType numberType = jp.getNumberType();
|
132
|
-
value = RubyUtils.rubyBignum(_ruby, jp.getBigIntegerValue());
|
133
|
-
callAddValue(value, getFieldName(cx));
|
134
|
-
break;
|
135
|
-
|
136
|
-
case VALUE_NUMBER_FLOAT:
|
137
|
-
value = RubyUtils.rubyBigDecimal(_ruby, jp.getDecimalValue());
|
138
|
-
callAddValue(value, getFieldName(cx));
|
139
|
-
break;
|
140
|
-
|
141
|
-
case VALUE_TRUE:
|
142
|
-
value = _ruby.newBoolean(Boolean.TRUE);
|
143
|
-
callAddValue(value, getFieldName(cx));
|
144
|
-
break;
|
145
|
-
|
146
|
-
case VALUE_FALSE:
|
147
|
-
value = _ruby.newBoolean(Boolean.FALSE);
|
148
|
-
callAddValue(value, getFieldName(cx));
|
149
|
-
break;
|
150
|
-
|
151
|
-
case VALUE_NULL: // should not get this but...
|
152
|
-
value = _ctx.nil;
|
153
|
-
callAddValue(value, getFieldName(cx));
|
154
|
-
break;
|
155
|
-
|
156
|
-
case END_ARRAY:
|
157
|
-
if (!_no_array_end) {
|
158
|
-
_array_end.call(_ctx, _handler, _meta, "array_end", getFieldName(cx));
|
159
|
-
}
|
160
|
-
break;
|
161
|
-
|
162
|
-
case END_OBJECT:
|
163
|
-
if (!_no_hash_end) {
|
164
|
-
_hash_end.call(_ctx, _handler, _meta, "hash_end", getFieldName(cx));
|
165
|
-
}
|
166
|
-
break;
|
167
|
-
}
|
168
|
-
}
|
169
|
-
}
|