Skip to content


AR: Serialized field won't be deserialized properly if class is not loaded at the deserialize moment #8596

phuongnd08 opened this Issue · 4 comments

2 participants


I create my custom struct with this:

class MyStruct <; end

And serialize it inside another model:

class MyModel < AR::Base
  serialize :data

And create a model: MyModel.create(data:

When I restart the Rails server, Calling return a string (it should return a struct)
It will return an object if I require 'my_struct' beforehand.

Ruby on Rails member

This is how it works. There is no information what class it should require, so you need to explicitly require it.

Ruby on Rails member

If you want to make it work pass MyStruct as second argument of serialize


Well, what if I have 10 types of Struct that I want to serialize into that field? then that does mean I have to require 10 times while they are already in rails auto load paths.

Ruby on Rails member

Unfortunately yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.