Skip to content

Commit

Permalink
Merge pull request #122 from excpt/refactor-json-dependency
Browse files Browse the repository at this point in the history
Remove obsolete json code
  • Loading branch information
excpt committed Jan 12, 2016
2 parents 1499b16 + 2d5bc86 commit b85b30e
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions lib/jwt/json.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,16 @@
require 'json'

module JWT
# JSON fallback implementation or ruby 1.8.x
module Json
if RUBY_VERSION >= '1.9' && !defined?(MultiJson)
require 'json'

def decode_json(encoded)
JSON.parse(encoded)
rescue JSON::ParserError
raise JWT::DecodeError, 'Invalid segment encoding'
end

def encode_json(raw)
JSON.generate(raw)
end

else
require 'multi_json'

def decode_json(encoded)
MultiJson.decode(encoded)
rescue MultiJson::LoadError
raise JWT::DecodeError, 'Invalid segment encoding'
end
def decode_json(encoded)
JSON.parse(encoded)
rescue JSON::ParserError
raise JWT::DecodeError, 'Invalid segment encoding'
end

def encode_json(raw)
MultiJson.encode(raw)
end
def encode_json(raw)
JSON.generate(raw)
end
end
end

0 comments on commit b85b30e

Please sign in to comment.