module SerialBox::Serializers::JSON

JSON adapter for {SerialBox}. Defines the following methods when included in a class:

This gives the class total ability to work with ‘JSON.parse` and `#to_json`.

Constants

JSON_CREATE_ID

@private

Public Instance Methods

as_json(*) click to toggle source

Converts this object into primitives suitable for JSON serialization.

@return [Hash, Array] A JSON-serializable object.

# File lib/serializers/json.rb, line 29
def as_json(*)
  hsh = {SerialBox::Serializers::JSON::JSON_CREATE_ID => self.class.name}
  self.class._serialbox_serializer.serialization_operations.each do |operation|
    operation.apply self, hsh
  end
  return hsh
end
to_json(*args) click to toggle source

Serializes this object as JSON.

@return [String] The JSON representation of this object.

# File lib/serializers/json.rb, line 41
def to_json(*args) as_json.to_json(*args) end