Class: Castkit::Serializers::DefaultSerializer
- Defined in:
- lib/castkit/serializers/default_serializer.rb
Overview
Default serializer for Castkit::DataObject instances.
Serializes attributes into a plain Ruby hash, applying access rules, nil/blank filtering, and nested structure handling. The output format supports JSON-compatible structures and respects the class-level serialization configuration.
Instance Method Summary collapse
-
#attributes ⇒ Hash{Symbol => Castkit::Attribute}
The attributes to serialize.
-
#call ⇒ Hash
Serializes the object to a hash.
-
#options ⇒ Hash
Serialization config flags like :root, :ignore_nil, :allow_unknown.
-
#unknown_attributes ⇒ Hash{Symbol => Object}
Unrecognized attributes captured during deserialization.
Methods inherited from Base
Instance Method Details
#attributes ⇒ Hash{Symbol => Castkit::Attribute}
Returns the attributes to serialize.
14 |
# File 'lib/castkit/serializers/default_serializer.rb', line 14 cattri :attributes, nil, expose: :read |
#call ⇒ Hash
Serializes the object to a hash.
Includes unknown attributes if configured, and wraps in a root key if defined.
27 28 29 30 31 32 |
# File 'lib/castkit/serializers/default_serializer.rb', line 27 def call result = serialize_attributes result.merge!(unknown_attributes) if [:allow_unknown] [:root] ? { [:root].to_sym => result } : result end |
#options ⇒ Hash
Returns serialization config flags like :root, :ignore_nil, :allow_unknown.
20 |
# File 'lib/castkit/serializers/default_serializer.rb', line 20 cattri :options, nil, expose: :read |
#unknown_attributes ⇒ Hash{Symbol => Object}
Returns unrecognized attributes captured during deserialization.
17 |
# File 'lib/castkit/serializers/default_serializer.rb', line 17 cattri :unknown_attributes, nil, expose: :read |