class Ingenico::Connect::SDK::DefaultImpl::DefaultMarshaller

marshals objects to and from JSON format. Currently supports marshalling and unmarshalling of classes that support class.new_from_hash and class#to_h

Public Instance Methods

marshal(request_object) click to toggle source

Marshals the request_object to a JSON string using request_object#to_h

# File lib/ingenico/connect/sdk/defaultimpl/default_marshaller.rb, line 17
def marshal(request_object)
    JSON.pretty_generate(request_object.to_h)
end
unmarshal(json_string, klass) click to toggle source

Unmarshals a JSON string into an object of type klass using klass.new_from_hash

# File lib/ingenico/connect/sdk/defaultimpl/default_marshaller.rb, line 22
def unmarshal(json_string, klass)
  if json_string.nil?
    return nil
  elsif json_string.length == 0
    return ''
  end
  if klass.respond_to?(:new_from_hash)
    klass.new_from_hash(JSON.load(json_string))
  else
    raise NotImplementedError
  end
end