Skip to content

Commit 4dd86fa

Browse files
committed
Add JrJackson adapter
1 parent 8695900 commit 4dd86fa

5 files changed

Lines changed: 28 additions & 5 deletions

File tree

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ platforms :ruby, :mswin, :mingw do
1515
end
1616
platforms :jruby do
1717
gem 'gson', '>= 0.6', :require => nil
18+
gem 'jrjackson', :require => nil
1819
end
1920

2021
group :development do

lib/multi_json.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def default_options=(value)
3131
['yajl', :yajl],
3232
['json', :json_gem],
3333
['gson', :gson],
34+
['jrjackson', :jrjackson],
3435
['json/pure', :json_pure]
3536
]
3637

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require 'jrjackson_r' unless defined?(::JrJackson)
2+
require 'multi_json/adapters/ok_json'
3+
4+
module MultiJson
5+
module Adapters
6+
class Jrjackson < MultiJson::Adapters::OkJson
7+
ParseError = ::Java::OrgCodehausJackson::JsonParseException
8+
9+
def load(string, options={}) #:nodoc:
10+
string = string.read if string.respond_to?(:read)
11+
result = ::JrJackson::Json.parse(string)
12+
options[:symbolize_keys] ? symbolize_keys(result) : result
13+
end
14+
15+
def dump(object, options={}) #:nodoc:
16+
::JrJackson::Json.generate(prepare_object(object){ |value| value })
17+
end
18+
end
19+
end
20+
end

spec/adapter_shared_example.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class << time
106106

107107
# This behavior is currently not supported by gson.rb
108108
# See discussion at https://github.com/intridea/multi_json/pull/71
109-
unless adapter == 'gson'
109+
unless %w(gson jrjackson).include?(adapter)
110110
it 'dumps custom objects that implement to_json' do
111111
klass = Class.new do
112112
def to_json(*)

spec/multi_json_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,11 @@
144144

145145
it_behaves_like 'has options', MultiJson
146146

147-
%w(gson json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
148-
next if adapter == 'gson' && !jruby?
149-
next if adapter == 'nsjsonserialization' && !macruby?
150-
next if jruby? && (adapter == 'oj' || adapter == 'yajl')
147+
%w(gson jrjackson json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
148+
next if !jruby? && %w(gson jrjackson).include?(adapter)
149+
next if !macruby? && adapter == 'nsjsonserialization'
150+
next if jruby? && %w(oj yajl).include?(adapter)
151+
151152
context adapter do
152153
it_behaves_like 'an adapter', adapter
153154
end

0 commit comments

Comments
 (0)