lib/datadog_api_client/v2/model_base.rb
# Deserializes the data based on type
# @param type [string] Data type
# @param value [string] Value to be deserialized
# @return [Object] Deserialized data
# @!visibility private
Deserializes the data based on type
Deserializes the data based on type
def _deserialize(type, value)
      case type.to_sym
      when :Time
      Time.parse(value)
      when :Date
        Date.parse(value)
      when :String
        value.to_s
      when :Integer
        value.to_i
      when :Float
        value.to_f
      when :Boolean
        if value.to_s =~ /\A(true|t|yes|y|1)\z/i
          true
        else
          false
        end
      when :Object
        value
      when :Array
        value
      when /\AArray<(?<inner_type>.+)>\z/
        inner_type = Regexp.last_match[:inner_type]
        value.map { |v| _deserialize(inner_type, v) }
      when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
        k_type = Regexp.last_match[:k_type]
        v_type = Regexp.last_match[:v_type]
        {}.tap do |hash|
          value.each do |k, v|
            hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
          end
        end
      else 
        s (e.g. Pet) or oneOf
        klass = DatadogAPIClient::V2.const_get(type)
        res = klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
        if res.instance_of? DatadogAPIClient::V2::UnparsedObject
          self._unparsed = true
        end
        res
      end
    end
def _deserialize ( type , value ) case type . to_sym when :Time Time . parse ( value ) when :Date Date . parse ( value ) when :String value . to_s when :Integer value . to_i when :Float value . to_f when :Boolean if value . to_s =~ / \A (true|t|yes|y|1) \z /i true else false end when :Object value when :Array value when / \A Array<(?<inner_type>.+)> \z / inner_type = Regexp . last_match [ :inner_type ] value . map { | v | _deserialize ( inner_type , v ) } when / \A Hash<(?<k_type>.+?), (?<v_type>.+)> \z / k_type = Regexp . last_match [ :k_type ] v_type = Regexp . last_match [ :v_type ] { } . tap do | hash | value . each do | k , v | hash [ _deserialize ( k_type , k ) ] = _deserialize ( v_type , v ) end end else klass = DatadogAPIClient :: V2 . const_get ( type ) res = klass . respond_to? ( :openapi_one_of ) ? klass . build ( value ) : klass . build_from_hash ( value ) if res . instance_of? DatadogAPIClient :: V2 :: UnparsedObject self . _unparsed = true end res end end
Deserializes the data based on type
Deserializes the data based on type
# generic object (usually a Hash), return directly # generic array, return directly # model # models (e.g. Pet) or oneOf
None
Object
type
None
value
Value to be deserialized
Value to be deserialized
!visibility
None