Class: Castkit::DefaultSerializer
- Inherits:
-
Serializer
- Object
- Serializer
- Castkit::DefaultSerializer
- Defined in:
- lib/castkit/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 Attribute Summary collapse
-
#attributes ⇒ Hash{Symbol => Castkit::Attribute}
readonly
The attributes to serialize.
-
#options ⇒ Hash
readonly
Serialization config flags like :root, :ignore_nil, :allow_unknown.
-
#unknown_attributes ⇒ Hash{Symbol => Object}
readonly
Unrecognized attributes captured during deserialization.
Attributes inherited from Serializer
Instance Method Summary collapse
-
#call ⇒ Hash
Serializes the object to a hash.
Methods inherited from Serializer
Instance Attribute Details
#attributes ⇒ Hash{Symbol => Castkit::Attribute} (readonly)
Returns the attributes to serialize.
13 14 15 |
# File 'lib/castkit/default_serializer.rb', line 13 def attributes @attributes end |
#options ⇒ Hash (readonly)
Returns serialization config flags like :root, :ignore_nil, :allow_unknown.
19 20 21 |
# File 'lib/castkit/default_serializer.rb', line 19 def @options end |
#unknown_attributes ⇒ Hash{Symbol => Object} (readonly)
Returns unrecognized attributes captured during deserialization.
16 17 18 |
# File 'lib/castkit/default_serializer.rb', line 16 def unknown_attributes @unknown_attributes end |
Instance Method Details
#call ⇒ Hash
Serializes the object to a hash.
Includes unknown attributes if configured, and wraps in a root key if defined.
26 27 28 29 30 31 |
# File 'lib/castkit/default_serializer.rb', line 26 def call result = serialize_attributes result.merge!(unknown_attributes) if [:allow_unknown] [:root] ? { [:root].to_sym => result } : result end |