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 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 Base
Instance Method Summary collapse
-
#call ⇒ Hash
Serializes the object to a hash.
Methods inherited from Base
Instance Attribute Details
#attributes ⇒ Hash{Symbol => Castkit::Attribute} (readonly)
Returns the attributes to serialize.
14 15 16 |
# File 'lib/castkit/serializers/default_serializer.rb', line 14 def attributes @attributes end |
#options ⇒ Hash (readonly)
Returns serialization config flags like :root, :ignore_nil, :allow_unknown.
20 21 22 |
# File 'lib/castkit/serializers/default_serializer.rb', line 20 def end |
#unknown_attributes ⇒ Hash{Symbol => Object} (readonly)
Returns unrecognized attributes captured during deserialization.
17 18 19 |
# File 'lib/castkit/serializers/default_serializer.rb', line 17 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.
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 |