Class: Wukong::Processor::FromJson

Inherits:
Serializer show all
Defined in:
lib/wukong/widget/serializers.rb

Overview

A widget for deserializing inputs from JSON.

Examples:

Deserializing from JSON at the beginning of a data flow


Wukong.dataflow(:consumes_json) do
  from_json | ...
end

See Also:

Constant Summary

Constants inherited from Wukong::Processor

SerializerError

Instance Attribute Summary

Attributes included from Hanuman::StageInstanceMethods

#graph

Instance Method Summary collapse

Methods inherited from Serializer

#handle_error

Methods inherited from Wukong::Processor

configure, description, #finalize, #perform_action, #receive_action, #setup, #stop

Methods included from Logging

included

Methods inherited from Hanuman::Stage

#clone

Methods included from Hanuman::StageClassMethods

#builder, #label, #register, #set_builder

Methods included from Hanuman::StageInstanceMethods

#add_link, #linkable_name, #root

Instance Method Details

#process(record) {|obj| ... } ⇒ Object

Yields the input record deserialized from JSON.

Parameters:

Yields:

  • (obj)

    the deserialized object

Yield Parameters:

  • obj (Object)


79
80
81
82
83
84
85
86
87
88
# File 'lib/wukong/widget/serializers.rb', line 79

def process(record)
  if record.respond_to?(:from_json)
    obj = record.from_json
  else
    obj = MultiJson.load(record)
  end
  yield obj
rescue => e
  handle_error(record, e)       
end