Is it by design? Because I was expecting it to work a bit different.
Suppose I have two Entities
class User < Hanami::Entity
attributes do
attribute :id, Types::Int
attribute :auth_data, Types::Entity(::UserAuthData)
end
end
class UserAuthData < Hanami::Entity
attributes do
attribute :hi, Types::String
end
end
I can initialize it that way
user_params = {id: 3, auth_data: {hi: "hello"}}
user = User.new(user_params)
now when I do user.to_h
{:id=>3,
:auth_data=>#<UserAuthData:0x000055d8e7fcf600 @attributes={:hi=>"hello"}>}
User entity is serialized to hash, but enclosed UserAuthData is still an object, we did not return to the same user_params
The only way I see to do that is
Hanami::Utils::Hash.new(user).to_hash
or
Hanami::Utils::Hash.deep_serialize(user)
these methods return {:id=>3, :auth_data=>{:hi=>"hello"}}
as expected
Maybe Entity object by itself need to have a helper to serialize itself to real nested hash?
Actually I would expect from entity_object.to_h
to do this by default, but maybe I miss some consideration.