At their heart, normalizers are for turning non-scalar data (entities and such) into scalar data (arrays, strings, ints, etc) and vice-versa. We have used them to do much more.

Here are two examples of the module encoding too much of the specification and doing de-Drupalization (i.e. field resolution).

http://cgit.drupalcode.org/jsonapi/tree/src/Normalizer/RelationshipItemN...
http://cgit.drupalcode.org/jsonapi/tree/src/Normalizer/JsonApiDocumentTo...

We should explore other techniques for handling this kind of logic and make our normalizers into more simple, side effect free, map functions.

Comments

gabesullice created an issue. See original summary.

e0ipso’s picture

Please take my comment in #2874601-50: refactor(QueryBuilder): Improve testability/maintainability WRT #43 into consideration when tackling this.

gabesullice’s picture

Title: [TASK] Normalizer simplification and refactoring » chore(Normalizer): Simplification and refactoring

@e0ipso, absolutely.

wim leers’s picture

wim leers’s picture

Issue tags: +maintainability

In #4, I linked to #2923779: Normalizers violate NormalizerInterface, which I believe is related.

JSON API is violating the NormalizerInterface spec by not returning array|scalar from ::normalize(), but instead returning value objects. This issue might remove the need for those value objects, and hence might end up solving that other issue.

gabesullice’s picture

Status: Active » Closed (outdated)
Related issues: +#2936754: Avoid using the Serialization component for JSON API specific tasks

I think the main discussion for this issue has moved to #2936754: Avoid using the Serialization component for JSON API specific tasks