[Serializer] Allow using attributes to declare compile-time serialization metadata #61532
+240
−21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Very close to #61528
Prerequisite for #61287
At the moment, serialization attributes are read at runtime when
framework.serialization.enable_attributes
is true.This means they don't fit for bundles nor can't they be warmed up.
This PR fixes both issues by using a new
serializer.attribute_metadata
resource tag, that's turned into a list of classes to parse for attributes at compile-time.For bundles and for apps, the tag is added by explicit service configuration:
Unlike validation where we have constraint attributes to auto-discover service resources, serialization doesn't have any corresponding hooks. We do have a few like
#[DiscriminatorMap]
of#[Groups]
, but relying on those would miss many more classes that are meant for serialization. Maybe we could introduce an attribute that'd hint that some class is serializable by the component (and require the attribute at some point in the future?)