Class: Ingenico::Connect::SDK::DefaultImpl::DefaultMarshaller
- Inherits:
-
Marshaller
- Object
- Marshaller
- Ingenico::Connect::SDK::DefaultImpl::DefaultMarshaller
- Defined in:
- lib/ingenico/connect/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
Constant Summary collapse
- @@INSTANCE =
DefaultMarshaller.new
Class Method Summary collapse
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.
Class Method Details
.INSTANCE ⇒ Object
11 12 13 |
# File 'lib/ingenico/connect/sdk/defaultimpl/default_marshaller.rb', line 11 def self.INSTANCE @@INSTANCE end |
Instance Method Details
#marshal(request_object) ⇒ Object
marshals the request_object to a JSON string using request_object#to_h
16 17 18 |
# File 'lib/ingenico/connect/sdk/defaultimpl/default_marshaller.rb', line 16 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
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ingenico/connect/sdk/defaultimpl/default_marshaller.rb', line 21 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 |