Module: Selenium::WebDriver::BiDi::Serialization::Record::Serializable Private

Defined in:
lib/selenium/webdriver/bidi/serialization/record.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.as_json(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



429
430
431
432
433
434
435
436
# File 'lib/selenium/webdriver/bidi/serialization/record.rb', line 429

def self.as_json(value)
  case value
  when Serializable then value.as_json
  when ::Array then value.map { |element| as_json(element) }
  when ::Hash then value.transform_values { |element| as_json(element) }
  else value
  end
end

Instance Method Details

#as_json ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Omit UNSET fields; emit null only for nullable ones.



439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/selenium/webdriver/bidi/serialization/record.rb', line 439

def as_json(*)
  payload = {}
  self.class.fields.each do |f|
    value = public_send(f.name)
    next if UNSET.equal?(value)
    next if value.nil? && !f.nullable

    value = Serialization.to_wire(value, Protocol.const_get(f.enum)) if f.enum
    payload[f.wire_key] = Serializable.as_json(value)
  end
  merge_extensions!(payload) if self.class.extensible? && !extensions.empty?
  payload
end