class XapianDb::TypeCodec::JsonCodec
Public Class Methods
decode(json_string)
click to toggle source
Decode an object from a json string @param [String] json_string a json string representing the object @return [Hash] a ruby hash
# File lib/type_codec.rb 44 def self.decode(json_string) 45 return nil if json_string.nil? || json_string == "" 46 begin 47 JSON.parse json_string 48 rescue TypeError 49 raise ArgumentError.new "'#{json_string}' cannot be parsed" 50 end 51 end
encode(object)
click to toggle source
Encode an object to its json representation @param [Object] object an object to encode @return [String] the json string
# File lib/type_codec.rb 32 def self.encode(object) 33 return nil if object.nil? 34 begin 35 object.to_json 36 rescue NoMethodError 37 raise ArgumentError.new "#{object} does not support json serialization" 38 end 39 end