Class: Operaton::Bpm::Client::Impl::ObjectMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/operaton/bpm/client/impl/object_mapper.rb

Overview

Stands in for the configured Jackson ObjectMapper: JSON encoding and decoding plus date handling with the client's configured date format.

The date format is a Ruby strftime pattern. The default corresponds to the Java client's "yyyy-MM-dd'T'HH:mm:ss.SSSZ".

Constant Summary collapse

DEFAULT_DATE_FORMAT =
"%Y-%m-%dT%H:%M:%S.%L%z"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date_format = DEFAULT_DATE_FORMAT) ⇒ ObjectMapper

Returns a new instance of ObjectMapper.



20
21
22
# File 'lib/operaton/bpm/client/impl/object_mapper.rb', line 20

def initialize(date_format = DEFAULT_DATE_FORMAT)
  @date_format = date_format
end

Instance Attribute Details

#date_formatObject (readonly)

Returns the value of attribute date_format.



18
19
20
# File 'lib/operaton/bpm/client/impl/object_mapper.rb', line 18

def date_format
  @date_format
end

Instance Method Details

#format_date(time) ⇒ Object



32
33
34
35
# File 'lib/operaton/bpm/client/impl/object_mapper.rb', line 32

def format_date(time)
  time = time.to_time if !time.is_a?(Time) && time.respond_to?(:to_time)
  time.strftime(date_format)
end

#parse_date(string) ⇒ Object



37
38
39
# File 'lib/operaton/bpm/client/impl/object_mapper.rb', line 37

def parse_date(string)
  Time.strptime(string, date_format)
end

#read_value(json_string) ⇒ Object



28
29
30
# File 'lib/operaton/bpm/client/impl/object_mapper.rb', line 28

def read_value(json_string)
  JSON.parse(json_string)
end

#write_value_as_string(value) ⇒ Object



24
25
26
# File 'lib/operaton/bpm/client/impl/object_mapper.rb', line 24

def write_value_as_string(value)
  JSON.generate(value)
end