-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider having a SerializableResource
and DeserializableDocument
#1098
Comments
My quick 2cts here:
|
@beauby As much as I agree with you that summarized: serializer = ActiveModel::Serializer.serializer_for(resource)
serializer_instance = serializer.new(resource, serializer_opts)
adapter_instance = ActiveModel::Serializer.adapter.new(serializer_instance, adapter_opts)
adapter_instance.serializable_hash(options) could be serializer = ActiveModel::Serializer.serializer_for(resource)
serializer_instance = serializer.new(resource, serializer_opts)
resource_serialization = ActiveModel::Serializer.resource_adapter.new(serializer_instance.serializable_hash)
adapter_instance = ActiveModel::Serializer.response_adapter.new(resource_serialization, adapter_opts)
adapter_instance.serializable_hash(options) Which since wouldn't really allow for Again, the serialization of Post as |
Per discussion in rails-api#1098
Hey everyone showing up late here:
👍 totally agree
I really like how the serializer worked solo, but having
Agree, we will need to split this logic, not sure if
👎 would be nice to keep adapter as simple as possible, if we fell the need to split it we might be putting more responsibilities in it than we should. So abou the PR itself:
|
re removing |
@rails-api/ams Has this been amply considered? Are we still interested in doing this? |
@remear This has kind of been forgotten. I still think it's a goo idea, but... |
Whereas
SerializableResource.serialize
return an instance ofSerializableResource
is not intuitive.SerializableResource.new
to return aserializable_resource
serializable_hash
,as_json
,to_json
that is usually consumed by the Renderer in RailsSerializableResource.serialize
andSerializableResource.deserialize
would get complicated quite quickly as they're really different responsibilitiesTherefore
SerializableResource
that takes a resource and aDeserializableDocument
that takes a JSON document. It might even make sense for theDeserializableDocument
to be a pure function since there may not need to be an intermediate state, as there is with theSerializableResource
.Also, we might start a convention of calling subclass of an ActiveModel::Serializer an e.g. PostSerialization
Relevant PRS
Some (lightly amended) discussion of what SerializableResource does (from the slack team)
The text was updated successfully, but these errors were encountered: