Sha256: 2610d94276c5b242b4385e6fa94f99e63158c64a79025d6e1cc2941b10e07909

Contents?: true

Size: 623 Bytes

Versions: 3

Compression:

Stored size: 623 Bytes

Contents

module JWT
  module Json
    if RUBY_VERSION >= "1.9" && !defined?(MultiJson)
      require 'json'

      def decode_json(encoded)
        JSON.parse(encoded)
      rescue JSON::ParserError
        raise JWT::DecodeError.new("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.new("Invalid segment encoding")
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jwt-1.2.1 lib/jwt/json.rb
jwt-1.2.0 lib/jwt/json.rb
jwt-1.0.0 lib/jwt/json.rb