Repository navigation
Reject documents with a class level normalizer - #33
Open
DavidBadura wants to merge 4 commits into
Open
DavidBadura wants to merge 4 commits into
DavidBadura wants to merge 4 commits into
Conversation
Hydrator 2 uses a normalizer on the class, a parent or an interface for the whole object, while v1 ignored it on the root class. A document is stored field by field, so such a normalizer breaks loading and storing in different ways. The metadata factory now fails early with DocumentHasClassNormalizer. To see the normalizer of the actual document class, FieldMappingResolver::resolve() gets the document class name next to the property, whose declaring class is often a parent. The check in DocumentHydrator::extract() stays as a type guard for custom hydrators.
FieldMappingResolver::resolve() now takes the document class and returns the mappings of all its properties. The class normalizer check runs once per class, so it also catches subclasses without visible properties of their own, for example when the root declares a private id. Since the stack hydrator resolver now walks the hydrator metadata instead of reflection, properties the hydrator does not store (#[Ignore], static) no longer crash the metadata build, and private properties of a parent class get a mapping like every other stored field.
The factory added an id and version mapping for every class of a hierarchy, even when the resolver did not return the property for that class. A resolver that cannot see a private id of the root from a subclass then produced a different id mapping for the subclass and a false DiscriminatorFieldConflict. The defaults are now only added once, after all classes are resolved.
The upgrade guide gets both changes, field-mapping.md and inheritance.md say that a document can not have a class level normalizer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hydrator 2 applies a class level normalizer (on the class, a parent, an interface or through a guesser) to the whole object. A document is stored field by field, so such a normalizer breaks loading and storing in different ways. The metadata factory now fails early with
DocumentHasClassNormalizer.To check the actual document class,
FieldMappingResolver::resolve()now works per class and returns the mappings of all its properties. That also catches subclasses without visible properties of their own, for example when the root declares a private id. Since the stack hydrator resolver now walks the hydrator metadata instead of reflection, ignored and static properties no longer crash the metadata build, and private properties of a parent class get mapped. The id and version defaults are only added where the resolver does not return them, so a custom resolver that can't see a private root id no longer causes a falseDiscriminatorFieldConflict.The interface change is in the upgrade guide.