jrjackson 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.jrubyrc +433 -0
- data/Gemfile +1 -1
- data/README.md +32 -23
- data/benchmarking/.jrubyrc +2 -2
- data/benchmarking/benchmark.rb +10 -58
- data/benchmarking/benchmark_threaded.rb +153 -0
- data/dependency-reduced-pom.xml +72 -0
- data/jrjackson.gemspec +11 -5
- data/lib/jrjackson/jars/jrjackson-1.2.2.jar +0 -0
- data/lib/jrjackson/jrjackson.rb +22 -18
- data/lib/jrjackson/version.rb +1 -2
- data/pom.xml +15 -10
- data/src/main/java/com/jrjackson/JrJacksonRaw.java +97 -12
- data/src/main/java/com/jrjackson/JrJacksonService.java +0 -6
- data/src/main/java/com/jrjackson/RubyJacksonModule.java +74 -0
- data/src/main/java/com/jrjackson/RubyObjectDeserializer.java +138 -222
- data/src/main/java/com/jrjackson/RubyObjectStrDeserializer.java +23 -0
- data/src/main/java/com/jrjackson/RubyObjectSymDeserializer.java +3 -60
- data/src/main/java/com/jrjackson/RubyUtils.java +77 -0
- data/src/test/java/com/jrjackson/jruby/AppTest.java +38 -0
- data/test/jrjackson_test.rb +63 -0
- metadata +17 -13
- data/lib/jrjackson/jars/jrjackson-1.0.jar +0 -0
- data/src/main/java/com/jrjackson/JrJacksonStr.java +0 -80
- data/src/main/java/com/jrjackson/JrJacksonSym.java +0 -80
@@ -1,80 +0,0 @@
|
|
1
|
-
package com.jrjackson;
|
2
|
-
|
3
|
-
import org.jruby.Ruby;
|
4
|
-
import org.jruby.RubyClass;
|
5
|
-
import org.jruby.RubyObject;
|
6
|
-
import org.jruby.RubyString;
|
7
|
-
import org.jruby.RubyIO;
|
8
|
-
import org.jruby.anno.JRubyMethod;
|
9
|
-
import org.jruby.anno.JRubyModule;
|
10
|
-
import org.jruby.exceptions.RaiseException;
|
11
|
-
import org.jruby.ext.stringio.RubyStringIO;
|
12
|
-
import org.jruby.java.addons.IOJavaAddons;
|
13
|
-
import org.jruby.javasupport.JavaUtil;
|
14
|
-
import org.jruby.runtime.ThreadContext;
|
15
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
16
|
-
import org.jruby.util.RubyDateFormat;
|
17
|
-
|
18
|
-
import java.io.InputStream;
|
19
|
-
import java.io.IOException;
|
20
|
-
import java.text.DateFormat;
|
21
|
-
import java.util.*;
|
22
|
-
|
23
|
-
import com.fasterxml.jackson.databind.ObjectMapper;
|
24
|
-
import com.fasterxml.jackson.databind.module.SimpleModule;
|
25
|
-
import com.fasterxml.jackson.core.Version;
|
26
|
-
import com.fasterxml.jackson.core.JsonProcessingException;
|
27
|
-
|
28
|
-
@JRubyModule(name = "JrJacksonSym")
|
29
|
-
public class JrJacksonSym extends RubyObject {
|
30
|
-
private static final ObjectMapper mapper = new ObjectMapper();
|
31
|
-
private static final SimpleModule module = new SimpleModule("JrJacksonSymModule");
|
32
|
-
|
33
|
-
static {
|
34
|
-
mapper.registerModule(module.addDeserializer(Object.class, RubyObjectSymDeserializer.instance));
|
35
|
-
mapper.setDateFormat(new RubyDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.US, true));
|
36
|
-
}
|
37
|
-
|
38
|
-
public JrJacksonSym(Ruby ruby, RubyClass metaclass) {
|
39
|
-
super(ruby, metaclass);
|
40
|
-
}
|
41
|
-
|
42
|
-
@JRubyMethod(module = true, name = {"parse", "load"}, required = 1)
|
43
|
-
public static IRubyObject parse(ThreadContext context, IRubyObject self, IRubyObject arg) {
|
44
|
-
Ruby ruby = context.getRuntime();
|
45
|
-
try {
|
46
|
-
Object o;
|
47
|
-
if (arg instanceof RubyString) {
|
48
|
-
o = mapper.readValue(arg.toString(), Object.class);
|
49
|
-
} else if ((arg instanceof RubyIO) || (arg instanceof RubyStringIO)) {
|
50
|
-
IRubyObject stream = IOJavaAddons.AnyIO.any_to_inputstream(context, arg);
|
51
|
-
o = mapper.readValue((InputStream)stream.toJava(InputStream.class), Object.class);
|
52
|
-
} else {
|
53
|
-
throw ruby.newArgumentError("Unsupported source. This method accepts String or IO");
|
54
|
-
}
|
55
|
-
return (RubyObject)JavaUtil.convertJavaToRuby(ruby, o);
|
56
|
-
}
|
57
|
-
catch (JsonProcessingException e) {
|
58
|
-
throw ParseError.newParseError(ruby, e.getLocalizedMessage());
|
59
|
-
}
|
60
|
-
catch (IOException e) {
|
61
|
-
throw ruby.newIOError(e.getLocalizedMessage());
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
@JRubyMethod(module = true, name = {"generate", "dump"}, required = 1)
|
66
|
-
public static IRubyObject generate(ThreadContext context, IRubyObject self, IRubyObject arg) {
|
67
|
-
Ruby ruby = context.getRuntime();
|
68
|
-
Object obj = arg.toJava(Object.class);
|
69
|
-
try {
|
70
|
-
String s = mapper.writeValueAsString(obj);
|
71
|
-
return ruby.newString(s);
|
72
|
-
}
|
73
|
-
catch (JsonProcessingException e) {
|
74
|
-
throw ParseError.newParseError(ruby, e.getLocalizedMessage());
|
75
|
-
}
|
76
|
-
catch (IOException e) {
|
77
|
-
throw ruby.newIOError(e.getLocalizedMessage());
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|