jrjackson 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -1
- data/README.md +59 -0
- data/Rakefile +1 -151
- data/benchmarking/.jrubyrc +434 -0
- data/benchmarking/benchmark.rb +92 -20
- data/jrjackson.gemspec +17 -16
- data/lib/jrjackson.rb +2 -10
- data/lib/jrjackson/jars/jrjackson-1.0.jar +0 -0
- data/lib/jrjackson/jrjackson.rb +44 -34
- data/lib/jrjackson/version.rb +1 -1
- data/lib/require_relative_patch.rb +6 -0
- data/pom.xml +86 -0
- data/src/main/java/com/jrjackson/JrJacksonRaw.java +76 -0
- data/src/main/java/com/jrjackson/JrJacksonService.java +29 -0
- data/src/main/java/com/jrjackson/JrJacksonStr.java +80 -0
- data/src/main/java/com/jrjackson/JrJacksonSym.java +80 -0
- data/src/main/java/com/jrjackson/ParseError.java +15 -0
- data/src/main/java/com/jrjackson/RubyObjectDeserializer.java +257 -0
- data/src/main/java/com/jrjackson/RubyObjectSymDeserializer.java +80 -0
- metadata +33 -22
- data/README +0 -44
- data/lib/jrjackson/jackson-core-asl-1.9.5.jar +0 -0
- data/lib/jrjackson/jackson-mapper-asl-1.9.5.jar +0 -0
- data/lib/jrjackson/jackson-smile-1.9.5.jar +0 -0
- data/lib/jrjackson/rubify.rb +0 -35
- data/lib/jrjackson/rubify_with_symbol_keys.rb +0 -34
- data/lib/jrjackson_r.rb +0 -11
- data/lib/jrjackson_r_sym.rb +0 -11
@@ -0,0 +1,80 @@
|
|
1
|
+
package com.jrjackson;
|
2
|
+
|
3
|
+
import java.io.IOException;
|
4
|
+
import java.util.*;
|
5
|
+
|
6
|
+
import com.fasterxml.jackson.core.*;
|
7
|
+
|
8
|
+
import com.fasterxml.jackson.databind.DeserializationContext;
|
9
|
+
import com.fasterxml.jackson.databind.DeserializationFeature;
|
10
|
+
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
|
11
|
+
import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
|
12
|
+
import com.fasterxml.jackson.databind.util.ObjectBuffer;
|
13
|
+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
14
|
+
|
15
|
+
import org.jruby.Ruby;
|
16
|
+
import org.jruby.RubyObject;
|
17
|
+
import org.jruby.RubyArray;
|
18
|
+
import org.jruby.RubyHash;
|
19
|
+
import org.jruby.RubyString;
|
20
|
+
import org.jruby.RubySymbol;
|
21
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
22
|
+
import org.jruby.javasupport.JavaUtil;
|
23
|
+
import org.jruby.javasupport.util.RuntimeHelpers;
|
24
|
+
|
25
|
+
|
26
|
+
public class RubyObjectSymDeserializer
|
27
|
+
// extends RubyObjectDeserializer<RubyObject>
|
28
|
+
extends RubyObjectDeserializer
|
29
|
+
{
|
30
|
+
|
31
|
+
protected final static Ruby __ruby__ = Ruby.getGlobalRuntime();
|
32
|
+
|
33
|
+
public final static RubyObjectSymDeserializer instance = new RubyObjectSymDeserializer();
|
34
|
+
|
35
|
+
public RubyObjectSymDeserializer() { super(); }
|
36
|
+
|
37
|
+
/*
|
38
|
+
/**********************************************************
|
39
|
+
/* Internal methods
|
40
|
+
/**********************************************************
|
41
|
+
*/
|
42
|
+
|
43
|
+
protected RubySymbol rubySymbol(JsonParser jp) throws IOException {
|
44
|
+
return __ruby__.newSymbol(jp.getText());
|
45
|
+
}
|
46
|
+
|
47
|
+
protected RubyObject mapObject(JsonParser jp, DeserializationContext ctxt)
|
48
|
+
throws IOException, JsonProcessingException
|
49
|
+
{
|
50
|
+
JsonToken t = jp.getCurrentToken();
|
51
|
+
if (t == JsonToken.START_OBJECT) {
|
52
|
+
t = jp.nextToken();
|
53
|
+
}
|
54
|
+
// 1.6: minor optimization; let's handle 1 and 2 entry cases separately
|
55
|
+
if (t != JsonToken.FIELD_NAME) { // and empty one too
|
56
|
+
// empty map might work; but caller may want to modify... so better just give small modifiable
|
57
|
+
return RubyHash.newHash(__ruby__);
|
58
|
+
}
|
59
|
+
RubySymbol field1 = rubySymbol(jp);
|
60
|
+
jp.nextToken();
|
61
|
+
RubyObject value1 = deserialize(jp, ctxt);
|
62
|
+
if (jp.nextToken() != JsonToken.FIELD_NAME) { // single entry; but we want modifiable
|
63
|
+
return RuntimeHelpers.constructHash(__ruby__, field1, value1);
|
64
|
+
}
|
65
|
+
RubySymbol field2 = rubySymbol(jp);
|
66
|
+
jp.nextToken();
|
67
|
+
RubyObject value2 = deserialize(jp, ctxt);
|
68
|
+
if (jp.nextToken() != JsonToken.FIELD_NAME) {
|
69
|
+
return RuntimeHelpers.constructHash(__ruby__, field1, value1, field2, value2);
|
70
|
+
}
|
71
|
+
RubyHash result = RuntimeHelpers.constructHash(__ruby__, field1, value1, field2, value2);
|
72
|
+
do {
|
73
|
+
RubySymbol fieldName = rubySymbol(jp);
|
74
|
+
jp.nextToken();
|
75
|
+
result.fastASet(fieldName, deserialize(jp, ctxt));
|
76
|
+
} while (jp.nextToken() != JsonToken.END_OBJECT);
|
77
|
+
return result;
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
metadata
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jrjackson
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Guy Boertje
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
version_requirements:
|
15
|
+
name: bundler
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - ~>
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: '1.0'
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
21
27
|
none: false
|
22
|
-
requirement: *2056
|
23
28
|
prerelease: false
|
24
29
|
type: :development
|
25
|
-
description:
|
30
|
+
description: A mostly native JRuby wrapper for the java jackson json processor jar
|
26
31
|
email:
|
27
32
|
- guyboertje@gmail.com
|
28
33
|
executables: []
|
@@ -30,21 +35,25 @@ extensions: []
|
|
30
35
|
extra_rdoc_files: []
|
31
36
|
files:
|
32
37
|
- Gemfile
|
33
|
-
- README
|
38
|
+
- README.md
|
34
39
|
- Rakefile
|
40
|
+
- benchmarking/.jrubyrc
|
35
41
|
- benchmarking/benchmark.rb
|
36
42
|
- jrjackson.gemspec
|
37
43
|
- lib/jrjackson.rb
|
38
|
-
- lib/jrjackson/
|
39
|
-
- lib/jrjackson/jackson-mapper-asl-1.9.5.jar
|
40
|
-
- lib/jrjackson/jackson-smile-1.9.5.jar
|
44
|
+
- lib/jrjackson/jars/jrjackson-1.0.jar
|
41
45
|
- lib/jrjackson/jrjackson.rb
|
42
|
-
- lib/jrjackson/rubify.rb
|
43
|
-
- lib/jrjackson/rubify_with_symbol_keys.rb
|
44
46
|
- lib/jrjackson/version.rb
|
45
|
-
- lib/
|
46
|
-
-
|
47
|
+
- lib/require_relative_patch.rb
|
48
|
+
- pom.xml
|
47
49
|
- profiling/profiled.rb
|
50
|
+
- src/main/java/com/jrjackson/JrJacksonRaw.java
|
51
|
+
- src/main/java/com/jrjackson/JrJacksonService.java
|
52
|
+
- src/main/java/com/jrjackson/JrJacksonStr.java
|
53
|
+
- src/main/java/com/jrjackson/JrJacksonSym.java
|
54
|
+
- src/main/java/com/jrjackson/ParseError.java
|
55
|
+
- src/main/java/com/jrjackson/RubyObjectDeserializer.java
|
56
|
+
- src/main/java/com/jrjackson/RubyObjectSymDeserializer.java
|
48
57
|
homepage: http://github.com/guyboertje/jrjackson
|
49
58
|
licenses: []
|
50
59
|
post_install_message:
|
@@ -53,21 +62,23 @@ require_paths:
|
|
53
62
|
- lib
|
54
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
55
64
|
requirements:
|
56
|
-
- -
|
65
|
+
- - ">="
|
57
66
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
67
|
+
version: !binary |-
|
68
|
+
MA==
|
59
69
|
none: false
|
60
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
71
|
requirements:
|
62
|
-
- -
|
72
|
+
- - ">="
|
63
73
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
74
|
+
version: !binary |-
|
75
|
+
MA==
|
65
76
|
none: false
|
66
77
|
requirements: []
|
67
78
|
rubyforge_project:
|
68
|
-
rubygems_version: 1.8.
|
79
|
+
rubygems_version: 1.8.24
|
69
80
|
signing_key:
|
70
81
|
specification_version: 3
|
71
82
|
summary: A JRuby wrapper for the java jackson json processor jar
|
72
83
|
test_files: []
|
73
|
-
|
84
|
+
has_rdoc:
|
data/README
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
jrjackson
|
2
|
-
|
3
|
-
a jruby library wrapping the JAVA jackson jars
|
4
|
-
|
5
|
-
provides:
|
6
|
-
|
7
|
-
JrJackson::Json.generate(obj) -> json string
|
8
|
-
JrJackson::Json.parse(str) -> hash like object
|
9
|
-
|
10
|
-
JrJackson::Smile.generate obj -> smile string
|
11
|
-
JrJackson::Smile.parse smile_str -> hash like object
|
12
|
-
|
13
|
-
|
14
|
-
Credit to Chuck Remes for the benchmark and initial
|
15
|
-
investigation when the jruby, json gem and the jackson
|
16
|
-
libraries were young.
|
17
|
-
|
18
|
-
I compared json-jruby 1.5.1 and jackson/smile 1.9.5 on jruby 1.6.7 and Java 7
|
19
|
-
|
20
|
-
user system total real
|
21
|
-
jackson generate: 0.756000 0.000000 0.756000 ( 0.756000)
|
22
|
-
smile generate: 0.530000 0.000000 0.530000 ( 0.530000)
|
23
|
-
ruby generate: 2.754000 0.000000 2.754000 ( 2.754000)
|
24
|
-
jackson parse: 0.630000 0.000000 0.630000 ( 0.630000)
|
25
|
-
smile parse: 0.368000 0.000000 0.368000 ( 0.368000)
|
26
|
-
ruby parse: 2.102000 0.000000 2.102000 ( 2.102000)
|
27
|
-
|
28
|
-
Variants:
|
29
|
-
|
30
|
-
jrjackson.rb
|
31
|
-
this variant is the fastest but the parse function will
|
32
|
-
return Java ArrayList instead of Ruby Array and
|
33
|
-
Java LinkedHashMap instead of Ruby Hash.
|
34
|
-
In Jruby 1.6.0+, these java classes have most if not all
|
35
|
-
of the behaviour of the corresponding Ruby classes
|
36
|
-
|
37
|
-
jrjackson_r.rb
|
38
|
-
If you absolutely need Ruby Objects then use this variant
|
39
|
-
It parses a little bit slower than the above but
|
40
|
-
returns Ruby Array and Hash objects
|
41
|
-
|
42
|
-
jrjackson_r_sym.rb
|
43
|
-
Will give you symbols for hash keys instead of strings
|
44
|
-
|
Binary file
|
Binary file
|
Binary file
|
data/lib/jrjackson/rubify.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
module JrJackson
|
2
|
-
include_package "org.codehaus.jackson.map.module"
|
3
|
-
java_import org.codehaus.jackson.map.deser.UntypedObjectDeserializer
|
4
|
-
java_import org.codehaus.jackson.Version
|
5
|
-
java_import org.codehaus.jackson.JsonToken
|
6
|
-
|
7
|
-
class RubyObjectDeserializer < UntypedObjectDeserializer
|
8
|
-
def mapArray(jp,ctxt)
|
9
|
-
arr = super(jp,ctxt)
|
10
|
-
arr.entries
|
11
|
-
end
|
12
|
-
|
13
|
-
def mapObject(jp,ctxt)
|
14
|
-
t = jp.getCurrentToken
|
15
|
-
t = jp.nextToken if t == JsonToken::START_OBJECT
|
16
|
-
|
17
|
-
return {} if t != JsonToken::FIELD_NAME
|
18
|
-
tmp = []
|
19
|
-
begin
|
20
|
-
k = jp.getText
|
21
|
-
jp.nextToken
|
22
|
-
v = deserialize(jp, ctxt)
|
23
|
-
tmp.push(k)
|
24
|
-
tmp.push(v)
|
25
|
-
end while jp.nextToken != JsonToken::END_OBJECT
|
26
|
-
Hash[*tmp]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
_module = SimpleModule.new("JrJacksonModule", Version.new(1, 0, 0, nil))
|
31
|
-
_module.addDeserializer(Jclass, RubyObjectDeserializer.new)
|
32
|
-
Mapper.registerModule(_module)
|
33
|
-
|
34
|
-
end
|
35
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module JrJackson
|
2
|
-
include_package "org.codehaus.jackson.map.module"
|
3
|
-
java_import org.codehaus.jackson.map.deser.UntypedObjectDeserializer
|
4
|
-
java_import org.codehaus.jackson.Version
|
5
|
-
java_import org.codehaus.jackson.JsonToken
|
6
|
-
|
7
|
-
class RubyObjectDeserializer < UntypedObjectDeserializer
|
8
|
-
def mapArray(jp,ctxt)
|
9
|
-
arr = super(jp,ctxt)
|
10
|
-
arr.entries
|
11
|
-
end
|
12
|
-
|
13
|
-
def mapObject(jp,ctxt)
|
14
|
-
t = jp.getCurrentToken
|
15
|
-
t = jp.nextToken if t == JsonToken::START_OBJECT
|
16
|
-
|
17
|
-
return {} if t != JsonToken::FIELD_NAME
|
18
|
-
tmp = []
|
19
|
-
begin
|
20
|
-
k = jp.getText
|
21
|
-
jp.nextToken
|
22
|
-
v = deserialize(jp, ctxt)
|
23
|
-
tmp.push(k.to_sym)
|
24
|
-
tmp.push(v)
|
25
|
-
end while jp.nextToken != JsonToken::END_OBJECT
|
26
|
-
Hash[*tmp]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
_module = SimpleModule.new("JrJacksonModule", Version.new(1, 0, 0, nil))
|
31
|
-
_module.addDeserializer(Jclass, RubyObjectDeserializer.new)
|
32
|
-
Mapper.registerModule(_module)
|
33
|
-
|
34
|
-
end
|
data/lib/jrjackson_r.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
unless RUBY_PLATFORM =~ /java/
|
2
|
-
error "This library is only compatible with a java-based ruby environment like JRuby."
|
3
|
-
exit 255
|
4
|
-
end
|
5
|
-
|
6
|
-
require 'java'
|
7
|
-
|
8
|
-
$CLASSPATH << 'jrjackson'
|
9
|
-
|
10
|
-
require File.join("jrjackson","jrjackson")
|
11
|
-
require File.join("jrjackson","rubify")
|
data/lib/jrjackson_r_sym.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
unless RUBY_PLATFORM =~ /java/
|
2
|
-
error "This library is only compatible with a java-based ruby environment like JRuby."
|
3
|
-
exit 255
|
4
|
-
end
|
5
|
-
|
6
|
-
require 'java'
|
7
|
-
|
8
|
-
$CLASSPATH << 'jrjackson'
|
9
|
-
|
10
|
-
require File.join("jrjackson","jrjackson")
|
11
|
-
require File.join("jrjackson","rubify_with_symbol_keys")
|