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,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <extensions>
3
+ <extension>
4
+ <groupId>io.takari.polyglot</groupId>
5
+ <artifactId>polyglot-ruby</artifactId>
6
+ <version>0.1.15</version>
7
+ </extension>
8
+ </extensions>
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ group :development do
5
+ gem 'gson', '>= 0.6'
6
+ gem 'json', '~> 1.8'
7
+ gem 'benchmark-ips'
8
+ end
9
+
10
+ gemspec
@@ -0,0 +1,32 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ VERSION='1.2.18'
4
+ gemspec :jar => "jrjackson/jars/jrjackson-#{VERSION}.jar"
5
+
6
+ # overwrite groupId:artifacgtId:version from gem
7
+ id "com.jrjackson.jruby:jrjackson:#{VERSION}"
8
+ packaging :jar
9
+
10
+
11
+ properties 'project.build.sourceEncoding' => 'UTF-8',
12
+ 'netbeans.hint.jdkPlatform' => 'JDK_1.8',
13
+ # create a pom.xml from this here
14
+ 'polyglot.dump.pom' => 'pom.xml'
15
+
16
+ jar 'junit:junit', '4.11', :scope => :test
17
+
18
+ jar 'org.jruby:jruby', '9.0.5.0', :scope => :provided
19
+
20
+ plugin :compiler, '3.1', :source => '1.7', :target => '1.7',
21
+ :showDeprecateion => false,
22
+ :showWarnings => false,
23
+ :executable => '${JAVA_HOME}/bin/javac',
24
+ :fork => true
25
+
26
+ plugin :surefire, '2.17', :skipTests => true
27
+
28
+ # since bundle install does not vendor our jars we need to it manually
29
+ plugin 'org.torquebox.mojo:jruby9-exec-maven-plugin', '0.3.1' do
30
+ execute_goal :exec, :id => 'vendor-jars', :phase => 'prepare-package',
31
+ :script => "require 'jars/installer';Jars::Installer.vendor_jars!"
32
+ end
@@ -0,0 +1,150 @@
1
+
2
+
3
+ LICENSE applicable to this library:
4
+
5
+ Apache License 2.0 see http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ ### JrJackson:
8
+
9
+ a jruby library wrapping the JAVA Jackson jars`
10
+
11
+ __NOTE:__ Smile support has been temporarily dropped
12
+
13
+ The code has been refactored to use almost all Java.
14
+
15
+ There is now a MultiJson adapter added for JrJackson.
16
+
17
+ This release is compatible with JRuby 9.0.0.0 and higher.
18
+
19
+ ***
20
+
21
+ #### NEWS
22
+
23
+ 07 October 2015 - during serialisation, check and execute `to_json_data` method
24
+ first.
25
+
26
+ 13th September 2015 - added support for a `to_json_data` method lookup.
27
+ Use this if you want to provide a JSON native data structure that best
28
+ represents your custom object.
29
+
30
+ 11th May 2014 - Added to_time method call for Ruby object serialization
31
+
32
+ 26th October 2013 - Added support to serialize arbitary (non JSON datatypes)
33
+ ruby objects. Normally the toJava internal method is called, but additionally
34
+ to_h, to_hash, to_a and finally to_json are tried. Be aware that the to_json
35
+ method might invoke a new selialization session (i.e. it may use the JSON gem)
36
+ and impact performance.
37
+
38
+ ***
39
+
40
+ #### API
41
+
42
+ ```
43
+ JrJackson::Json.load(string, options) -> hash like object
44
+ aliased as parse
45
+ ```
46
+ By default the load method will return Ruby objects (Hashes have string keys).
47
+ The options hash respects three symbol keys
48
+
49
+ + :symbolize_keys
50
+
51
+ Will return symbol keys in hashes
52
+
53
+ + :raw
54
+
55
+ Will return JRuby wrapped java objects that quack like ruby objects
56
+ This is the fastest option but not by much
57
+
58
+ + :use_bigdecimal
59
+
60
+ Will return BigDecimal objects instead of Float.
61
+ If used with the :raw option you will get Java::JavaMath::BigDecimal objects
62
+ otherwise they are Ruby BigDecimal
63
+
64
+ + :use_smallint
65
+
66
+ Will return Integers objects instead of BigInteger
67
+
68
+ ```
69
+ JrJackson::Json.dump(obj) -> json string
70
+ aliased as generate
71
+ ```
72
+ The dump method expects that the values of hashes or arrays are JSON data types,
73
+ the only exception to this is Ruby Symbol as values, they are converted to java strings
74
+ during serialization. __NOTE:__ All other objects should be converted to JSON data types before
75
+ serialization. See the wiki for more on this.
76
+
77
+ ***
78
+
79
+ #### Internals
80
+
81
+ There are four Ruby sub modules of the JrJackson module
82
+
83
+ ```JrJackson::Json```, this is the general external facade used by MultiJson.
84
+
85
+ ```JrJackson::Raw```, this exists for backward compatibility, do not use this for new code.
86
+
87
+ ```JrJackson::Ruby```, this is used by the external facade, you should use this directly. It returns Ruby objects e.g. Hash, Array, Symbol, String, Integer, BigDecimal etc.
88
+
89
+ ```JrJackson::Java```, this is used by the external facade, you should use this directly. It returns Java objects e.g. ArrayList, HashMap, BigDecimal, BigInteger, Long, Float and String, JRuby wraps (mostly) them in a JavaProxy Ruby object.
90
+
91
+ ***
92
+
93
+ #### Benchmarks
94
+
95
+ Credit to Chuck Remes for the benchmark and initial
96
+ investigation when the jruby, json gem and the jackson
97
+ libraries were young.
98
+
99
+ I compared Json (java) 1.8.3, Gson 0.6.1 and jackson 2.6.1 on jruby 1.7.22 and Oracle Java HotSpot(TM) 64-Bit Server VM 1.8.0_60-b27 +jit [linux-amd64]
100
+ All the benchmarks were run separately. A 727.9KB string of random json data is read from a file and handled 250 times, thereby attempting to balance invocation and parsing benchmarking.
101
+
102
+ ```
103
+ generation/serialize
104
+
105
+ user system total real
106
+
107
+
108
+ json java generate: 250 6.780 0.620 7.400 ( 6.599)
109
+ gson generate: 250 4.480 0.530 5.010 ( 4.688)
110
+ jackson generate: 250 2.200 0.010 2.210 ( 2.128)
111
+
112
+ json mri parse: 250 9.620 0.000 9.620 ( 9.631)
113
+ oj mri parse: 250 9.190 0.000 9.190 ( 9.199)
114
+ json mri generate: 250 8.400 0.010 8.410 ( 8.419)
115
+ oj mri generate: 250 6.980 0.010 6.990 ( 6.999)
116
+
117
+
118
+ parsing/deserialize - after jrjackson parsing profiling
119
+
120
+ user system total real
121
+ json java parse: 250 9.320 0.580 9.900 ( 9.467)
122
+ jackson parse string keys: 250 3.600 0.520 4.120 ( 3.823)
123
+ jackson parse string + bigdecimal: 250 3.390 0.640 4.030 ( 3.721)
124
+ jackson parse ruby compat: 250 3.700 0.030 3.730 ( 3.516)
125
+ jackson parse ruby ootb: 250 3.490 0.120 3.610 ( 3.420)
126
+ jackson parse sj: 250 3.290 0.030 3.320 ( 3.065)
127
+ jackson parse symbol keys: 250 3.050 0.120 3.170 ( 2.943)
128
+ jackson parse symbol + bigdecimal: 250 2.770 0.020 2.790 ( 2.669)
129
+ jackson parse java + bigdecimal: 250 1.880 0.430 2.310 ( 2.239)
130
+ jackson parse java + bigdecimal direct: 250 1.950 0.440 2.390 ( 2.290)
131
+ jackson parse java ootb: 250 1.990 0.030 2.020 ( 1.925)
132
+ jackson parse java sym bd: 250 1.920 0.000 1.920 ( 1.898)
133
+ ```
134
+
135
+ I have done IPS style benchmarks too.
136
+
137
+ Generation
138
+ ```
139
+ jrjackson: 74539.4 i/s
140
+ gson: 58288.3 i/s - 1.28x slower
141
+ JSON: 54597.2 i/s - 1.37x slower
142
+ ```
143
+
144
+ Parsing returning Ruby
145
+ ```
146
+ symbol keys
147
+ jrjackson: 95203.9 i/s
148
+ JSON: 40712.0 i/s - 2.34x slower
149
+
150
+ ```
@@ -0,0 +1,10 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ desc "Run benchmarks"
7
+ task :benchmark do
8
+ load 'benchmarking/benchmark.rb'
9
+ end
10
+
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ require 'benchmark/ips'
3
+ require 'json'
4
+ require File.expand_path('lib/jrjackson')
5
+
6
+ obj = {
7
+ :name => "Fredrick Smith",
8
+ :quantity => 1_000_000,
9
+ :addresses => {
10
+ :address1 => "12 Heather Street, Parnell, Auckland, New Zealand",
11
+ :address2 => "1 Queen Street, CBD, Auckland, New Zealand"
12
+ }
13
+ }
14
+
15
+ json = JSON.dump(obj)
16
+
17
+ puts "Decode ====================="
18
+
19
+ puts 'Sleeping'
20
+ sleep 45
21
+ puts 'Working'
22
+
23
+ # -JXrunhprof:cpu=samples,depth=30,file=jrjackson.hprof
24
+
25
+ Benchmark.ips do |x|
26
+ x.config(time: 20, warmup: 20)
27
+
28
+ x.report("JrJackson new Ruby") { JrJackson::Ruby.parse(json, nil) }
29
+ # x.report("JrJackson Raw") { JrJackson::Java.parse(json, nil) }
30
+ # x.report("JSON") { JSON.load(json) }
31
+
32
+ # x.report("JrJackson") { JrJackson::Raw.parse_sym(json) }
33
+
34
+ # x.compare!
35
+ end
36
+
37
+ # puts "Encode ====================="
38
+ # Benchmark.ips do |x|
39
+ # x.config(time: 5, warmup: 10)
40
+
41
+ # x.report("JrJackson Raw") { JrJackson::Base.generate(obj) }
42
+ # x.report("JrJackson") { JrJackson::Json.dump(obj) }
43
+ # x.report("JSON") { JSON.dump(obj) }
44
+
45
+ # x.compare!
46
+ # end
@@ -0,0 +1,131 @@
1
+ v0.3.9
2
+ Thanks to mkristian, now uses jar_dependencies
3
+ Upgrade to Jackson v2.7.1
4
+ fix for issue 51
5
+ dont create "new RubyJacksonModule()" when creating a Provider
6
+ fix for reports of symbol table overflow in Jackson when using JrJackson in very long running daemons (Logstash)
7
+ disable the FAIL_ON_SYMBOL_HASH_OVERFLOW setting
8
+
9
+ v0.3.8
10
+ fix for issue 47
11
+ Update Jackson to v 2.6.3
12
+ Change error message to better report failure in issue 46
13
+
14
+ v0.3.7
15
+ fix for issue 46
16
+ Add references to RubyAnySerializer so Jackson can
17
+ use it for Ruby objects nested in Java objects
18
+
19
+ v0.3.6
20
+ fix for issue 45
21
+ use bytelist.begin instead of 0 generating from RubyString
22
+
23
+ v0.3.5
24
+ give highest precedence to the to_json_data method
25
+
26
+ v0.3.4
27
+ fix multi_json bug
28
+ not serializing non-string keys
29
+
30
+ v0.3.3
31
+ fix bigdecimal bug
32
+ add require bigdecimal
33
+
34
+ v0.3.2
35
+ update changelog
36
+
37
+ v0.3.1
38
+ remove old jar
39
+
40
+ v0.3.0
41
+ this is a major refactor.
42
+ parse and generate performance improvements.
43
+ see JrJackson::Ruby and JrJackson::Java modules
44
+ pretty generation support.
45
+ jruby 9.0.1.0 and 1.7.22
46
+ jackson 2.6.1
47
+
48
+ v0.2.9
49
+ fix for issue 39
50
+ incorrect error when serializing BasicObject
51
+
52
+ v0.2.8
53
+ fixes for issues-28,29,31
54
+ correction for Time#to_s
55
+ new options to control date serialization
56
+ optimizations suggested by @headius
57
+ jar compiled for jruby 1.7.17
58
+ jruby 1.7.17
59
+ jackson 2.4.4
60
+
61
+ v0.2.7
62
+ fixes for issues-23,24
63
+ add to_time as option for serializing Time like objects
64
+ jar compiled for jruby 1.7.11
65
+
66
+ v0.2.6
67
+ fix issue-20
68
+ allow jruby to convert Ruby StringIO into Java
69
+ by not type checking passed arg
70
+ this is because jruby 1.7.9 has changed the type of java object backing Ruby StringIO
71
+ jar compiled for jruby 1.7.8 (jruby 1.7.9 in the maven repo has an error in the pom.xml)
72
+ jruby 1.7.8, jruby 1.7.9 (tested)
73
+ jackson 2.3.0
74
+
75
+ v0.2.5
76
+ fix issue-16
77
+ reduce the gem size by:
78
+ change pom.xml to only include relevant java jars
79
+ exclude benchmaking from the gemspec files
80
+ jruby 1.7.5
81
+ jackson 2.2.3
82
+
83
+ v0.2.4
84
+ fix issue-15
85
+ return Ruby nil instead of Java null
86
+ fix issue-14
87
+ remove all usage of Ruby.getGlobalRuntime
88
+ pass the runtime from the calling Ruby ThreadContext into the deserializers and converters
89
+ jruby 1.7.5
90
+ jackson 2.2.3
91
+
92
+ v0.2.3
93
+ fix issue-12
94
+ improve the serialization support for non Json Datatype Ruby objects
95
+ now has support for serializing via toJava, to_h, to_hash, to_a, to_json
96
+ fix for failing MultiJson unicode test
97
+ jruby 1.7.4
98
+ jackson 2.2.3
99
+
100
+ v0.2.2
101
+ fix issue-13
102
+ compile Java for 1.6 compatibility
103
+ documentation tweaks
104
+ jruby 1.7.4
105
+ jackson 2.2.3
106
+
107
+ v0.2.1
108
+ documentation tweaks
109
+ fix issue-7
110
+ add pluggable String and Symbol Converters for JSON values
111
+ jruby 1.7.4
112
+ jackson 2.2.3
113
+
114
+ v0.2.0
115
+ extract all Java -> Ruby generation to reusable RubyUtils static class
116
+ support BigDecimal
117
+ remove JSON Api
118
+ fixes issues 5, 6, 8,
119
+
120
+ jruby 1.7.3
121
+ jackson 2.2.2
122
+
123
+ v0.1.1
124
+ fix Time regex
125
+ v0.1.0
126
+ MutiJson compatibility
127
+ switch to using almost all Java, i.e. define most of the ruby modules in Java
128
+ jruby 1.7.3
129
+ jackson 2.1.4
130
+ v0.0.7
131
+ first release - minimal jruby wrapper around jackson 1.9.5 jars
@@ -0,0 +1,32 @@
1
+ #! /usr/bin/env jruby
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'jrjackson/build_info'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = 'jrjackson'
9
+ s.version = JrJackson::BuildInfo.version
10
+ s.date = JrJackson::BuildInfo.release_date
11
+ # need java platform for jar-dependencies to work
12
+ s.platform = 'java'
13
+ s.authors = ['Guy Boertje']
14
+ s.email = ['guyboertje@gmail.com']
15
+ s.homepage = "http://github.com/guyboertje/jrjackson"
16
+ s.summary = %q{A JRuby wrapper for the java jackson json processor jar}
17
+ s.description = %q{A mostly native JRuby wrapper for the java jackson json processor jar}
18
+ s.license = 'Apache License 2.0'
19
+
20
+ s.add_development_dependency 'bundler', '~> 1.10'
21
+ s.add_development_dependency 'jar-dependencies', '< 2.0', '>= 0.3.2'
22
+ s.add_development_dependency 'ruby-maven', '~>3.3.10'
23
+
24
+ JACKSON_VERSION = '2.7.1'
25
+ s.requirements << "jar com.fasterxml.jackson.core:jackson-core, #{JACKSON_VERSION}"
26
+ s.requirements << "jar com.fasterxml.jackson.core:jackson-annotations, #{JACKSON_VERSION}"
27
+ s.requirements << "jar com.fasterxml.jackson.core:jackson-databind, #{JACKSON_VERSION}"
28
+ s.requirements << "jar com.fasterxml.jackson.module:jackson-module-afterburner, #{JACKSON_VERSION}"
29
+
30
+ s.files = JrJackson::BuildInfo.files
31
+
32
+ end
@@ -0,0 +1,2 @@
1
+ require "require_relative_patch" unless Kernel.respond_to?(:require_relative)
2
+ require_relative "jrjackson/jrjackson"
@@ -0,0 +1,15 @@
1
+ module JrJackson
2
+ module BuildInfo
3
+ def self.version
4
+ '0.3.9'
5
+ end
6
+
7
+ def self.release_date
8
+ '2016-04-09'
9
+ end
10
+
11
+ def self.files
12
+ `git ls-files`.split($/).select{|f| f !~ /\Abenchmarking/}
13
+ end
14
+ end
15
+ end