Skip to content

Reject documents with a class level normalizer - #33

Open
DavidBadura wants to merge 4 commits into
2.0.xfrom
class-level-normalizer
Open

DavidBadura wants to merge 4 commits into
2.0.xfrom
class-level-normalizer

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

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 false DiscriminatorFieldConflict.

The interface change is in the upgrade guide.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant