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.
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,152 +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 com.fasterxml.jackson.core.JsonEncoding;
9
- import com.fasterxml.jackson.core.JsonFactory;
10
- import com.fasterxml.jackson.core.JsonGenerator;
11
- import com.fasterxml.jackson.core.JsonParser;
12
- import com.fasterxml.jackson.core.JsonProcessingException;
13
- import com.fasterxml.jackson.databind.ObjectMapper;
14
- import com.fasterxml.jackson.databind.SerializerProvider;
15
- import org.jcodings.specific.UTF8Encoding;
16
- import org.jruby.Ruby;
17
- import org.jruby.RubyClass;
18
- import org.jruby.RubyHash;
19
- import org.jruby.RubyIO;
20
- import org.jruby.RubyObject;
21
- import org.jruby.RubyString;
22
- import org.jruby.RubySymbol;
23
- import org.jruby.anno.JRubyMethod;
24
- import org.jruby.exceptions.RaiseException;
25
- import org.jruby.ext.stringio.StringIO;
26
- import org.jruby.runtime.ThreadContext;
27
- import org.jruby.runtime.builtin.IRubyObject;
28
- import org.jruby.util.ByteList;
29
-
30
- import java.io.ByteArrayOutputStream;
31
- import java.io.IOException;
32
- import java.text.SimpleDateFormat;
33
- import java.util.TimeZone;
34
-
35
- /**
36
- *
37
- * @author guy
38
- */
39
- public class JrJacksonBase extends RubyObject {
40
-
41
- // serialize
42
- @JRubyMethod(module = true, name = {"generate", "dump"}, required = 1, optional = 1)
43
- public static IRubyObject generate(ThreadContext context, IRubyObject self, IRubyObject[] args)
44
- throws IOException, RaiseException {
45
- Ruby _ruby = context.runtime;
46
- RubyHash options = (args.length <= 1) ? RubyHash.newHash(_ruby) : args[1].convertToHash();
47
- String format = (String) options.get(RubyUtils.rubySymbol(_ruby, "date_format"));
48
-
49
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
50
- JsonGenerator jgen = RubyJacksonModule.factory.createGenerator(
51
- baos, JsonEncoding.UTF8);
52
-
53
- if (flagged(options, RubyUtils.rubySymbol(_ruby, "pretty"))) {
54
- jgen.useDefaultPrettyPrinter();
55
- }
56
-
57
- SerializerProvider provider;
58
- if (format != null) {
59
- SimpleDateFormat simpleFormat = new SimpleDateFormat(format);
60
- String timezone = (String) options.get(RubyUtils.rubySymbol(_ruby, "timezone"));
61
- if (timezone != null) {
62
- simpleFormat.setTimeZone(TimeZone.getTimeZone(timezone));
63
- }
64
- provider = RubyJacksonModule.createProvider(simpleFormat);
65
- } else {
66
- provider = RubyJacksonModule.createProvider();
67
- }
68
-
69
- try {
70
- RubyAnySerializer.instance.serialize(args[0], jgen, provider);
71
- jgen.close();
72
- ByteList bl = new ByteList(baos.toByteArray(),
73
- UTF8Encoding.INSTANCE);
74
- return RubyString.newString(_ruby, bl);
75
- } catch (JsonProcessingException e) {
76
- throw ParseError.newParseError(_ruby, e.getLocalizedMessage());
77
- }
78
- }
79
-
80
- protected static boolean flagged(RubyHash opts, RubySymbol key) {
81
- Object val = opts.get(key);
82
- if (val == null) {
83
- return false;
84
- }
85
- boolean flag = (Boolean) val;
86
- return flag;
87
- }
88
-
89
- protected static boolean flagged(RubyHash opts, RubySymbol key, boolean returnVal) {
90
- if (!opts.containsKey(key)) {
91
- return returnVal;
92
- }
93
- Object val = opts.get(key);
94
- if (val == null) {
95
- return returnVal;
96
- }
97
- boolean flag = (Boolean) val;
98
- return flag;
99
- }
100
-
101
- protected static IRubyObject _sjcparse(ThreadContext context, IRubyObject handler, IRubyObject arg, IRubyObject opts, StreamParse sp) throws RaiseException {
102
-
103
- JsonParser jp;
104
- try {
105
- jp = buildParser(context, RubyJacksonModule.factory, arg);
106
- } catch (IOException e) {
107
- throw context.runtime.newIOError(e.getLocalizedMessage());
108
- }
109
- return sp.deserialize(jp);
110
- }
111
-
112
- protected static JsonParser buildParser(ThreadContext ctx, JsonFactory jf, IRubyObject arg) throws IOException {
113
- if (arg instanceof RubyString) {
114
- return jf.createParser(((RubyString) arg).getByteList().bytes());
115
- } else if (arg instanceof StringIO) {
116
- RubyString content = (RubyString) ((StringIO) arg).string(ctx);
117
- return jf.createParser(content.getByteList().bytes());
118
- } else {
119
- // must be an IO object then
120
- return jf.createParser(((RubyIO) arg).getInStream());
121
- }
122
- }
123
-
124
- protected static IRubyObject _parse(ThreadContext context, IRubyObject arg, ObjectMapper mapper) throws IOException, RaiseException {
125
- Ruby ruby = context.runtime;
126
- // same format as Ruby Time #to_s
127
- SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
128
- mapper.setDateFormat(simpleFormat);
129
- try {
130
- Object o;
131
- if (arg instanceof RubyString) {
132
- o = mapper.readValue(((RubyString) arg).getByteList().bytes(), Object.class);
133
- } else if (arg instanceof StringIO) {
134
- RubyString content = (RubyString) ((StringIO) arg).string(context);
135
- o = mapper.readValue(content.getByteList().bytes(), Object.class);
136
- } else {
137
- // must be an IO object then
138
- o = mapper.readValue(((RubyIO) arg).getInStream(), Object.class);
139
- }
140
- return RubyUtils.rubyObject(ruby, o);
141
- } catch (JsonProcessingException e) {
142
- throw ParseError.newParseError(ruby, e.getLocalizedMessage());
143
- } catch (IOException e) {
144
- throw ruby.newIOError(e.getLocalizedMessage());
145
- }
146
- }
147
-
148
- public JrJacksonBase(Ruby runtime, RubyClass metaClass) {
149
- super(runtime, metaClass);
150
- }
151
-
152
- }
@@ -1,81 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonParser;
4
- import org.jruby.Ruby;
5
- import org.jruby.RubyClass;
6
- import org.jruby.anno.JRubyModule;
7
- import org.jruby.anno.JRubyMethod;
8
- import org.jruby.runtime.ThreadContext;
9
- import org.jruby.runtime.builtin.IRubyObject;
10
-
11
- import java.io.IOException;
12
-
13
- import com.fasterxml.jackson.core.JsonProcessingException;
14
- import org.jruby.RubyHash;
15
- import org.jruby.exceptions.RaiseException;
16
-
17
-
18
- @JRubyModule(name = "JrJacksonJava")
19
- public class JrJacksonJava extends JrJacksonBase {
20
-
21
- public JrJacksonJava(Ruby ruby, RubyClass metaclass) {
22
- super(ruby, metaclass);
23
- }
24
-
25
- // deserialize
26
- @JRubyMethod(module = true, name = {"parse", "load"}, required = 2)
27
- public static IRubyObject parse(ThreadContext context, IRubyObject self, IRubyObject arg, IRubyObject opts)
28
- throws JsonProcessingException, IOException, RaiseException {
29
-
30
- JavaConverter ikonv = new JavaBigIntValueConverter();
31
- JavaConverter dkonv = new JavaBigDecimalValueConverter();
32
- if (opts != context.nil) {
33
- RubyHash options = opts.convertToHash();
34
- if (options.size() > 0) {
35
- if (!flagged(options,
36
- RubyUtils.rubySymbol(context.runtime, "use_bigdecimal"), true)) {
37
- dkonv = new JavaFloatValueConverter();
38
- }
39
- if (flagged(options,
40
- RubyUtils.rubySymbol(context.runtime, "use_smallint"))) {
41
- ikonv = new JavaLongValueConverter();
42
- }
43
- }
44
- }
45
-
46
- JavaHandler handler = new JavaHandler(ikonv, dkonv);
47
- JjParse parse = new JjParse(handler);
48
- JsonParser jp;
49
- try {
50
- jp = buildParser(context, RubyJacksonModule.factory, arg);
51
- } catch (IOException e) {
52
- throw context.runtime.newIOError(e.getLocalizedMessage());
53
- }
54
-
55
- parse.deserialize(jp);
56
- jp.close();
57
- return RubyUtils.rubyObject(context.runtime, handler.getResult());
58
- }
59
-
60
- // deserialize
61
- @JRubyMethod(module = true, name = {"parse_raw", "load_raw"}, required = 2)
62
- public static IRubyObject parse_raw(ThreadContext context, IRubyObject self, IRubyObject arg, IRubyObject opts)
63
- throws JsonProcessingException, IOException, RaiseException {
64
-
65
- JavaConverter ikonv = new JavaBigIntValueConverter();
66
- JavaConverter dkonv = new JavaBigDecimalValueConverter();
67
-
68
- JavaHandler handler = new JavaHandler(ikonv, dkonv);
69
- JjParse parse = new JjParse(handler);
70
- JsonParser jp;
71
- try {
72
- jp = buildParser(context, RubyJacksonModule.factory, arg);
73
- } catch (IOException e) {
74
- throw context.runtime.newIOError(e.getLocalizedMessage());
75
- }
76
-
77
- parse.deserialize(jp);
78
- jp.close();
79
- return RubyUtils.rubyObject(context.runtime, handler.getResult());
80
- }
81
- }
@@ -1,108 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import org.jruby.Ruby;
4
- import org.jruby.RubyClass;
5
- import org.jruby.RubyHash;
6
- import org.jruby.anno.JRubyMethod;
7
- import org.jruby.anno.JRubyModule;
8
- import org.jruby.runtime.ThreadContext;
9
- import org.jruby.runtime.builtin.IRubyObject;
10
-
11
- import java.io.IOException;
12
-
13
- import com.fasterxml.jackson.databind.ObjectMapper;
14
- import com.fasterxml.jackson.databind.DeserializationFeature;
15
- import org.jruby.exceptions.RaiseException;
16
-
17
-
18
- @JRubyModule(name = "JrJacksonRaw")
19
- public class JrJacksonRaw extends JrJacksonBase {
20
-
21
- public JrJacksonRaw(Ruby ruby, RubyClass metaclass) {
22
- super(ruby, metaclass);
23
- }
24
-
25
- // deserialize
26
- @JRubyMethod(module = true, name = {"parse", "load"}, required = 2)
27
- public static IRubyObject parse(ThreadContext context, IRubyObject self, IRubyObject arg, IRubyObject opts)
28
- throws IOException {
29
- Ruby _ruby = context.runtime;
30
- RubyHash options = null;
31
-
32
- if (opts != context.nil) {
33
- options = opts.convertToHash();
34
-
35
- return direct(context, self, arg,
36
- flagged(options, RubyUtils.rubySymbol(_ruby, "use_bigdecimal")),
37
- !flagged(options, RubyUtils.rubySymbol(_ruby, "use_smallint")),
38
- flagged(options, RubyUtils.rubySymbol(_ruby, "symbolize_keys")),
39
- flagged(options, RubyUtils.rubySymbol(_ruby, "raw")));
40
-
41
- } else {
42
- return direct(context, self, arg, false, true, false, false);
43
- }
44
- }
45
-
46
- private static IRubyObject direct(ThreadContext context, IRubyObject self, IRubyObject arg,
47
- boolean use_big_decimal, boolean use_big_int,
48
- boolean use_symbols, boolean use_raw) throws IOException {
49
- ObjectMapper local = RubyJacksonModule.rawBigNumberMapper();
50
-
51
- RubyConverter vci = new RubyIntValueConverter();
52
- RubyConverter vcf = new RubyFloatValueConverter();
53
- RubyKeyConverter kcn;
54
-
55
- if (use_big_decimal) {
56
- vcf = new RubyBigDecimalValueConverter();
57
- } else {
58
- local.disable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);
59
- }
60
-
61
- if (use_big_int) {
62
- vci = new RubyBigIntValueConverter();
63
- } else {
64
- local.disable(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS);
65
- }
66
-
67
- if(use_raw) {
68
- return _parse(context, arg, local);
69
- }
70
-
71
- if (use_symbols) {
72
- kcn = new RubySymbolKeyConverter();
73
- } else {
74
- kcn = new RubyStringKeyConverter();
75
- }
76
-
77
- local = RubyJacksonModule.mapperWith(context.runtime, kcn, vci, vcf);
78
- return _parse(context, arg, local);
79
- }
80
-
81
- @JRubyMethod(module = true, name = {"parse_raw", "load_raw"}, required = 1)
82
- public static IRubyObject parse_raw(ThreadContext context, IRubyObject self, IRubyObject arg)
83
- throws IOException, RaiseException {
84
- return direct(context, self, arg, false, false, false, true);
85
- }
86
-
87
- @JRubyMethod(module = true, name = {"parse_raw_bd", "load_raw_bd"}, required = 1)
88
- public static IRubyObject parse_raw_bd(ThreadContext context, IRubyObject self, IRubyObject arg)
89
- throws IOException, RaiseException {
90
-
91
- return direct(context, self, arg, true, true, false, true);
92
- }
93
-
94
- @JRubyMethod(module = true, name = {"parse_sym", "load_sym"}, required = 1)
95
- public static IRubyObject parse_sym(ThreadContext context, IRubyObject self, IRubyObject arg)
96
- throws IOException, RaiseException {
97
-
98
- return direct(context, self, arg, false, false, true, false);
99
- }
100
-
101
- @JRubyMethod(module = true, name = {"parse_str", "load_str"}, required = 1)
102
- public static IRubyObject parse_str(ThreadContext context, IRubyObject self, IRubyObject arg)
103
- throws IOException, RaiseException {
104
-
105
- return direct(context, self, arg, false, true, false, false);
106
-
107
- }
108
- }
@@ -1,89 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonFactory;
4
- import com.fasterxml.jackson.core.JsonParser;
5
- import org.jruby.Ruby;
6
- import org.jruby.RubyClass;
7
- import org.jruby.anno.JRubyModule;
8
- import org.jruby.anno.JRubyMethod;
9
- import org.jruby.runtime.ThreadContext;
10
- import org.jruby.runtime.builtin.IRubyObject;
11
-
12
- import java.io.IOException;
13
-
14
- import com.fasterxml.jackson.databind.ObjectMapper;
15
- import com.fasterxml.jackson.core.JsonProcessingException;
16
- import static com.jrjackson.JrJacksonBase.flagged;
17
- import org.jruby.RubyHash;
18
- import org.jruby.exceptions.RaiseException;
19
-
20
- @JRubyModule(name = "JrJacksonRuby")
21
- public class JrJacksonRuby extends JrJacksonBase {
22
-
23
- public JrJacksonRuby(Ruby ruby, RubyClass metaclass) {
24
- super(ruby, metaclass);
25
- }
26
-
27
- // deserialize
28
- @JRubyMethod(module = true, name = {"parse_sym", "load_sym"}, required = 2)
29
- public static IRubyObject parse_sym(ThreadContext context, IRubyObject self, IRubyObject arg, IRubyObject opts)
30
- throws JsonProcessingException, IOException, RaiseException {
31
-
32
- return __parse(context, arg,
33
- new RubySymbolNameConverter(),
34
- new RubyBigIntValueConverter(),
35
- new RubyBigDecimalValueConverter()
36
- );
37
- }
38
-
39
- @JRubyMethod(module = true, name = {"parse", "load"}, required = 2)
40
- public static IRubyObject parse(ThreadContext context, IRubyObject self, IRubyObject arg, IRubyObject opts)
41
- throws JsonProcessingException, IOException, RaiseException {
42
-
43
- RubyNameConverter konv = new RubyStringNameConverter();
44
- RubyConverter ikonv = new RubyBigIntValueConverter();
45
- RubyConverter dkonv = new RubyBigDecimalValueConverter();
46
- if (opts != context.nil) {
47
- RubyHash options = opts.convertToHash();
48
- if (options.size() > 0) {
49
- if (flagged(options,
50
- RubyUtils.rubySymbol(context.runtime, "symbolize_keys"))) {
51
- konv = new RubySymbolNameConverter();
52
- }
53
- if (!flagged(options,
54
- RubyUtils.rubySymbol(context.runtime, "use_bigdecimal"), true)) {
55
- dkonv = new RubyFloatValueConverter();
56
- }
57
- if (flagged(options,
58
- RubyUtils.rubySymbol(context.runtime, "use_smallint"))) {
59
- ikonv = new RubyIntValueConverter();
60
- }
61
- }
62
- }
63
- return __parse(context, arg, konv, ikonv, dkonv);
64
- }
65
-
66
- private static IRubyObject __parse(ThreadContext context, IRubyObject arg,
67
- RubyNameConverter keykonv, RubyConverter intconv, RubyConverter decimalconv)
68
- throws JsonProcessingException, IOException, RaiseException {
69
-
70
- RubyHandler handler = new RubyHandler(context,
71
- keykonv,
72
- intconv,
73
- decimalconv);
74
- JrParse parse = new JrParse(handler);
75
- ObjectMapper mapper = RubyJacksonModule.rawBigNumberMapper();
76
- JsonFactory jf = mapper.getFactory().disable(JsonFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW);
77
- JsonParser jp;
78
- try {
79
-
80
- jp = buildParser(context, jf, arg);
81
-
82
- } catch (IOException e) {
83
- throw context.runtime.newIOError(e.getLocalizedMessage());
84
- }
85
- parse.deserialize(jp);
86
- jp.close();
87
- return handler.getResult();
88
- }
89
- }
@@ -1,26 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import org.jruby.Ruby;
4
- import org.jruby.RubyClass;
5
- import org.jruby.anno.JRubyMethod;
6
- import org.jruby.anno.JRubyModule;
7
- import org.jruby.runtime.ThreadContext;
8
- import org.jruby.runtime.builtin.IRubyObject;
9
-
10
- import org.jruby.exceptions.RaiseException;
11
-
12
- @JRubyModule(name = "JrJacksonSaj")
13
- public class JrJacksonSaj extends JrJacksonBase {
14
-
15
- public JrJacksonSaj(Ruby ruby, RubyClass metaclass) {
16
- super(ruby, metaclass);
17
- }
18
-
19
- // deserialize
20
- @JRubyMethod(module = true, name = {"parse", "load"}, required = 3)
21
- public static IRubyObject parse(ThreadContext context, IRubyObject self, IRubyObject handler, IRubyObject arg, IRubyObject opts)
22
- throws RaiseException {
23
- StreamParse sp = new SajParse(context, handler);
24
- return _sjcparse(context, handler, arg, opts, sp);
25
- }
26
- }
@@ -1,25 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import org.jruby.Ruby;
4
- import org.jruby.RubyClass;
5
- import org.jruby.anno.JRubyMethod;
6
- import org.jruby.anno.JRubyModule;
7
- import org.jruby.runtime.ThreadContext;
8
- import org.jruby.runtime.builtin.IRubyObject;
9
- import org.jruby.exceptions.RaiseException;
10
-
11
- @JRubyModule(name = "JrJacksonSch")
12
- public class JrJacksonSch extends JrJacksonBase {
13
-
14
- public JrJacksonSch(Ruby ruby, RubyClass metaclass) {
15
- super(ruby, metaclass);
16
- }
17
-
18
- // deserialize
19
- @JRubyMethod(module = true, name = {"parse", "load"}, required = 3)
20
- public static IRubyObject parse(ThreadContext context, IRubyObject self, IRubyObject handler, IRubyObject arg, IRubyObject opts)
21
- throws RaiseException {
22
- StreamParse sp = new SchParse(context, handler);
23
- return _sjcparse(context, handler, arg, opts, sp);
24
- }
25
- }
@@ -1,38 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import org.jruby.Ruby;
4
- import org.jruby.RubyModule;
5
- import org.jruby.RubyClass;
6
- import org.jruby.runtime.load.BasicLibraryService;
7
-
8
- import java.io.IOException;
9
-
10
- public class JrJacksonService implements BasicLibraryService {
11
-
12
- @Override
13
- public boolean basicLoad(final Ruby ruby) throws IOException {
14
- RubyModule jr_jackson = ruby.defineModule("JrJackson");
15
-
16
- RubyModule jr_jackson_base = ruby.defineModuleUnder("Base", jr_jackson);
17
- jr_jackson_base.defineAnnotatedMethods(JrJacksonBase.class);
18
-
19
- RubyModule jr_jackson_raw = ruby.defineModuleUnder("Raw", jr_jackson);
20
- jr_jackson_raw.defineAnnotatedMethods(JrJacksonRaw.class);
21
-
22
- RubyModule jr_jackson_ruby = ruby.defineModuleUnder("Ruby", jr_jackson);
23
- jr_jackson_ruby.defineAnnotatedMethods(JrJacksonRuby.class);
24
-
25
- RubyModule jr_jackson_java = ruby.defineModuleUnder("Java", jr_jackson);
26
- jr_jackson_java.defineAnnotatedMethods(JrJacksonJava.class);
27
-
28
- RubyModule jr_jackson_saj = ruby.defineModuleUnder("Saj", jr_jackson);
29
- jr_jackson_saj.defineAnnotatedMethods(JrJacksonSaj.class);
30
-
31
- RubyModule jr_jackson_sch = ruby.defineModuleUnder("Sch", jr_jackson);
32
- jr_jackson_sch.defineAnnotatedMethods(JrJacksonSch.class);
33
-
34
- RubyClass runtimeError = ruby.getRuntimeError();
35
- RubyClass parseError = jr_jackson.defineClassUnder("ParseError", runtimeError, runtimeError.getAllocator());
36
- return true;
37
- }
38
- }
@@ -1,142 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import com.fasterxml.jackson.core.JsonParser;
4
- import com.fasterxml.jackson.core.JsonStreamContext;
5
- import org.jruby.RubyArray;
6
- import org.jruby.RubyHash;
7
- import org.jruby.runtime.builtin.IRubyObject;
8
-
9
- import java.io.IOException;
10
- import java.util.HashMap;
11
-
12
-
13
- /**
14
- *
15
- * @author Guy Boertje
16
- */
17
- public class JrParse {
18
- private final RubyHandler _handler;
19
- private final HashMap<JsonStreamContext, IRubyObject> _objectMap = new HashMap<JsonStreamContext, IRubyObject>();
20
- private JsonStreamContext _deepestContext;
21
-
22
- public JrParse(RubyHandler handler) {
23
- _handler = handler;
24
- }
25
-
26
- public void deserialize(JsonParser jp) throws IOException {
27
- try {
28
-
29
- while (jp.nextValue() != null) {
30
- handleRubyToken(jp);
31
- }
32
- } catch (IOException e) {
33
- _handler.raiseError(e.getLocalizedMessage());
34
- }
35
- }
36
-
37
- private void addRubyValue(JsonStreamContext x) {
38
- JsonStreamContext px = x.getParent();
39
- IRubyObject dtarget = _objectMap.get(_deepestContext);
40
-
41
- if (px == null) {
42
- _handler.addValue(dtarget);
43
- return;
44
- }
45
-
46
- IRubyObject value = _objectMap.get(x);
47
-
48
- if (x.inArray()) {
49
- _handler.arrayAppend(
50
- (RubyArray)value, dtarget);
51
- } else if (x.inObject()) {
52
- _handler.hashSet(
53
- (RubyHash)value, getRubyHashKey(x), dtarget);
54
-
55
- } else {
56
- _handler.addValue(value);
57
- }
58
- }
59
-
60
- private void addRubyValue(JsonStreamContext x, IRubyObject val) {
61
-
62
- if (x.inArray()) {
63
- RubyArray a = (RubyArray)_objectMap.get(x);
64
- _handler.arrayAppend(a, val);
65
- } else if (x.inObject()) {
66
- RubyHash h = (RubyHash)_objectMap.get(x);
67
- _handler.hashSet(h, getRubyHashKey(x), val);
68
-
69
- } else {
70
- _handler.addValue(val);
71
- }
72
- }
73
-
74
- private IRubyObject getRubyHashKey(JsonStreamContext x) {
75
- String k = x.getCurrentName();
76
- if (k == null) {
77
- return _handler.treatNull();
78
- }
79
- return _handler.hashKey(k);
80
- }
81
-
82
- protected void handleRubyToken(JsonParser jp)
83
- throws IOException {
84
-
85
- JsonStreamContext cx = jp.getParsingContext();
86
-
87
- switch (jp.getCurrentToken()) {
88
- case START_OBJECT:
89
- _deepestContext = cx;
90
- _objectMap.put(cx, _handler.hashStart());
91
- break;
92
-
93
- case START_ARRAY:
94
- _deepestContext = cx;
95
- _objectMap.put(cx, _handler.arrayStart());
96
-
97
- case FIELD_NAME:
98
- break;
99
-
100
- case VALUE_EMBEDDED_OBJECT:
101
- System.out.println("-------- VALUE_EMBEDDED_OBJECT ????????? --------");
102
- System.out.println(jp.getEmbeddedObject());
103
- break;
104
-
105
- case VALUE_STRING:
106
- addRubyValue(cx, _handler.treatString(jp));
107
- break;
108
-
109
- case VALUE_NUMBER_INT:
110
- addRubyValue(cx, _handler.treatInt(jp));
111
- break;
112
-
113
- case VALUE_NUMBER_FLOAT:
114
- addRubyValue(cx, _handler.treatFloat(jp));
115
- break;
116
-
117
- case VALUE_TRUE:
118
- addRubyValue(cx, _handler.trueValue());
119
- break;
120
-
121
- case VALUE_FALSE:
122
- addRubyValue(cx, _handler.falseValue());
123
- break;
124
-
125
- case VALUE_NULL: // should not get this but...
126
- addRubyValue(cx, _handler.treatNull());
127
- break;
128
-
129
- case END_ARRAY:
130
- _handler.arrayEnd();
131
- addRubyValue(cx);
132
- _deepestContext = cx;
133
- break;
134
-
135
- case END_OBJECT:
136
- _handler.hashEnd();
137
- addRubyValue(cx);
138
- _deepestContext = cx;
139
- break;
140
- }
141
- }
142
- }
@@ -1,16 +0,0 @@
1
- package com.jrjackson;
2
-
3
- import org.jruby.Ruby;
4
- import org.jruby.RubyClass;
5
- import org.jruby.RubyException;
6
- import org.jruby.anno.JRubyClass;
7
- import org.jruby.exceptions.RaiseException;
8
-
9
- @JRubyClass(name = "JrJackson::ParseError", parent = "RuntimeError")
10
- public class ParseError {
11
-
12
- public static RaiseException newParseError(Ruby ruby, String message) {
13
- RubyClass errorClass = ruby.getModule("JrJackson").getClass("ParseError");
14
- return new RaiseException(RubyException.newException(ruby, errorClass, message), true);
15
- }
16
- }