Class: AWS::Core::Options::JSONSerializer
- Inherits:
-
Object
- Object
- AWS::Core::Options::JSONSerializer
- Defined in:
- lib/aws/core/options/json_serializer.rb
Overview
Given a hash of serialization rules, a JSONSerializer can convert a hash of request options into a JSON document. The request options are validated before returning JSON.
Instance Attribute Summary collapse
- #namespace ⇒ String readonly
-
#operation_name ⇒ String
readonly
Returns the name of the API operation.
- #rules ⇒ Hash readonly
Instance Method Summary collapse
-
#initialize(rules, payload_param) ⇒ JSONSerializer
constructor
A new instance of JSONSerializer.
- #serialize!(request_options) ⇒ String
Constructor Details
#initialize(rules, payload_param) ⇒ JSONSerializer
Returns a new instance of JSONSerializer.
28 29 30 31 |
# File 'lib/aws/core/options/json_serializer.rb', line 28 def initialize rules, payload_param @payload_param = payload_param @rules = @payload_param ? rules[@payload_param][:members] : rules end |
Instance Attribute Details
#namespace ⇒ String (readonly)
37 38 39 |
# File 'lib/aws/core/options/json_serializer.rb', line 37 def namespace @namespace end |
#operation_name ⇒ String (readonly)
Returns the name of the API operation.
34 35 36 |
# File 'lib/aws/core/options/json_serializer.rb', line 34 def operation_name @operation_name end |
#rules ⇒ Hash (readonly)
40 41 42 |
# File 'lib/aws/core/options/json_serializer.rb', line 40 def rules @rules end |
Instance Method Details
#serialize!(request_options) ⇒ String
47 48 49 50 51 52 53 54 |
# File 'lib/aws/core/options/json_serializer.rb', line 47 def serialize = [@payload_param] if @payload_param data = normalize_keys(, rules) if rules.any?{|k,v| v[:location] == 'body' } data = data.values.first end JSON.pretty_generate(data) end |