Browse files

Add JrJackson adapter

  • Loading branch information...
1 parent 8695900 commit 4dd86fa96300aaaf6d762578b9b31ea82adb056d @rwz rwz committed Mar 9, 2013
Showing with 28 additions and 5 deletions.
  1. +1 −0 Gemfile
  2. +1 −0 lib/multi_json.rb
  3. +20 −0 lib/multi_json/adapters/jrjackson.rb
  4. +1 −1 spec/adapter_shared_example.rb
  5. +5 −4 spec/multi_json_spec.rb
View
1 Gemfile
@@ -15,6 +15,7 @@ platforms :ruby, :mswin, :mingw do
end
platforms :jruby do
gem 'gson', '>= 0.6', :require => nil
+ gem 'jrjackson', :require => nil
end
group :development do
View
1 lib/multi_json.rb
@@ -31,6 +31,7 @@ def default_options=(value)
['yajl', :yajl],
['json', :json_gem],
['gson', :gson],
+ ['jrjackson', :jrjackson],
['json/pure', :json_pure]
]
View
20 lib/multi_json/adapters/jrjackson.rb
@@ -0,0 +1,20 @@
+require 'jrjackson_r' unless defined?(::JrJackson)
+require 'multi_json/adapters/ok_json'
+
+module MultiJson
+ module Adapters
+ class Jrjackson < MultiJson::Adapters::OkJson

I'm a little late to the party, but should this be "JrJackson"? Or was the name deliberately changed?

@sferik
INTRIDEA Inc. member
sferik added a note Mar 18, 2013

Ah, yes, you're right. I'll fix this and push 1.7.1.

@sferik
INTRIDEA Inc. member
sferik added a note Mar 18, 2013

I just pushed 1.7.1 but then I realized that this breaks the build on JRuby: https://travis-ci.org/intridea/multi_json/builds/5601902

Basically, the specs expect the convention of camelCase class names to correspond to snake_case file names, so the options are:
1) Revert 5373a5e
2) Change jrjackson.rb to jr_jackson.rb
3) Rewrite the specs to manually map adapter class names to file names

I'm open to suggestions on which of these solutions is most desirable. I don't believe this change is causing any issues for users but I'd like to get the specs passing again.

Gotcha. The only problem I had with the old name is if you wanted to manually specify the adapter, it was a bit confusing and seemed error-prone. I guess I would be in favor of option 2. That goes against the filename convention in JrJackson, but I don't think that really matters here. Project should be able to name files whatever they want.

@sferik
INTRIDEA Inc. member
sferik added a note Mar 18, 2013

@nirvdrum Would you mind submitting a pull request making that change? I don't have time at the moment.

Sure thing. It might take me a day or so. I need to get some Rails security stuff out the door first.

@rwz
INTRIDEA Inc. member
rwz added a note Mar 19, 2013

That's the reason I named it Jrjackson, and not JrJackson in the first place. I think we can come up with a system of aliases, so for example MultiJson.use :jrjackson and MultiJson.use :jr_jackson would do the same thing.

I can prepare a fix for that today I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ ParseError = ::Java::OrgCodehausJackson::JsonParseException
+
+ def load(string, options={}) #:nodoc:
+ string = string.read if string.respond_to?(:read)
+ result = ::JrJackson::Json.parse(string)
+ options[:symbolize_keys] ? symbolize_keys(result) : result
+ end
+
+ def dump(object, options={}) #:nodoc:
+ ::JrJackson::Json.generate(prepare_object(object){ |value| value })
+ end
+ end
+ end
+end
View
2 spec/adapter_shared_example.rb
@@ -106,7 +106,7 @@ class << time
# This behavior is currently not supported by gson.rb
# See discussion at https://github.com/intridea/multi_json/pull/71
- unless adapter == 'gson'
+ unless %w(gson jrjackson).include?(adapter)
it 'dumps custom objects that implement to_json' do
klass = Class.new do
def to_json(*)
View
9 spec/multi_json_spec.rb
@@ -144,10 +144,11 @@
it_behaves_like 'has options', MultiJson
- %w(gson json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
- next if adapter == 'gson' && !jruby?
- next if adapter == 'nsjsonserialization' && !macruby?
- next if jruby? && (adapter == 'oj' || adapter == 'yajl')
+ %w(gson jrjackson json_gem json_pure nsjsonserialization oj ok_json yajl).each do |adapter|
+ next if !jruby? && %w(gson jrjackson).include?(adapter)
+ next if !macruby? && adapter == 'nsjsonserialization'
+ next if jruby? && %w(oj yajl).include?(adapter)
+
context adapter do
it_behaves_like 'an adapter', adapter
end

0 comments on commit 4dd86fa

Please sign in to comment.