Skip to content

Support for read_attribute_before_type_cast #196

@kalsan

Description

@kalsan

Hi! Hope you're doing well.

Using active_type with custom serialization breaks because calling read_attribute_before_type_cast on a ActiveType::Object returns nil. I've managed to work around the problem by implementing the following in the custom serializer:

raw_data = defined?(ActiveType::Object) && is_a?(ActiveType::Object) ? virtual_attributes[attribute_name.to_s] : read_attribute_before_type_cast(attribute_name)
result = my_custom_type_value.deserialize(raw_data)

I thus suspect that overriding read_attribute_before_type_cast in active_type and having it return virtual_attributes[attribute_name] would likely fix this. However, I'm not sure about compatibility with different Rails versions.

What do you think, would this be a sensible way to fix this problem?

Best,
Kalsan

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions