Class: Ingenico::Direct::SDK::DefaultImpl::DefaultMarshaller
- Inherits:
-
Marshaller
- Object
- Marshaller
- Ingenico::Direct::SDK::DefaultImpl::DefaultMarshaller
- Includes:
- Singleton
- Defined in:
- lib/ingenico/direct/sdk/defaultimpl/default_marshaller.rb
Overview
marshals objects to and from JSON format. Currently supports marshalling and unmarshalling of classes that support class.new_from_hash and class#to_h
Instance Method Summary collapse
-
#marshal(request_object) ⇒ Object
Marshals the request_object to a JSON string using request_object#to_h.
-
#unmarshal(json_string, klass) ⇒ Object
Unmarshals a JSON string into an object of type klass using klass.new_from_hash.
Instance Method Details
#marshal(request_object) ⇒ Object
Marshals the request_object to a JSON string using request_object#to_h
17 18 19 |
# File 'lib/ingenico/direct/sdk/defaultimpl/default_marshaller.rb', line 17 def marshal(request_object) JSON.pretty_generate(request_object.to_h) end |
#unmarshal(json_string, klass) ⇒ Object
Unmarshals a JSON string into an object of type klass using klass.new_from_hash
23 24 25 26 27 28 29 |
# File 'lib/ingenico/direct/sdk/defaultimpl/default_marshaller.rb', line 23 def unmarshal(json_string, klass) return nil unless json_string return '' if json_string.empty? return klass.new_from_hash(JSON.parse(json_string)) if klass.respond_to?(:new_from_hash) raise NotImplementedError end |