MapDefinitionNormalizer and ContextDefinitionNormalizer break REST serialization (same as #3568588)
### Steps to reproduce 1. Install Drupal 11.x with the REST module enabled and a content entity exposed via a `ResourceBase` plugin that calls `$serializer->normalize($entity, 'json')` (e.g. any custom REST resource that returns entities as normalized arrays). 2. Enable the Tool module (verified on 1.0.0-alpha9, 1.0.0-beta1, and 1.0.x-dev). 3. Request the REST endpoint and inspect the JSON response — or reproduce directly via `drush php:eval`: ```php $node = \Drupal::entityTypeManager()->getStorage('node')->load(1); print_r(\Drupal::service('serializer')->normalize($node, 'json')); ``` ### Expected behavior Field values are present in the output, e.g.: ```json {"title":[{"value":"Hello"}], "uid":[{"target_id":1, ...}], ...} ``` This is what Drupal core's `FieldItemNormalizer` produces, and what every REST resource that relies on the global serializer depends on. ### Actual behavior Field cardinality is preserved but every value is `null`: ```json {"title":[null], "uid":[null], "field_multi":[null,null,null], ...} ``` Root cause: - `MapDefinitionNormalizer` and `ContextDefinitionNormalizer` are tagged as global normalizers at priority **100** (higher than core's `FieldItemNormalizer`). - Both extend `ComplexDataNormalizer`, whose inherited `supportsNormalization()` matches any `ComplexDataInterface`. - Every Drupal `FieldItem` extends `Map`, which implements `ComplexDataInterface`, so these normalizers claim FieldItem normalization for **every** format. - `getSupportedTypes()` declares e.g. `[Map::class => ($format === 'json_schema')]`, but in Symfony Serializer a `false` value means *"fall back to `supportsNormalization()`"*, not *"deny"*. So the format restriction is not actually enforced. - `doNormalize()` returns `NULL` for any format other than `json_schema` → all FieldItem values become `null` in REST responses. Disabling the Tool module restores correct serialization. This is the same class of bug as [#3568588: LegacyTypedDataNormalizer conflicts with JSON:API serialization](https://www.drupal.org/project/tool/issues/3568588), fixed for `LegacyTypedDataNormalizer` in MR !69 — but the same fix was not applied to `MapDefinitionNormalizer` or `ContextDefinitionNormalizer`. ### Proposed resolution Apply the same fix pattern as MR !69 to both remaining normalizers — return an empty array from `getSupportedTypes()` for non-`json_schema` formats so the Symfony Serializer skips them entirely: ```php public function getSupportedTypes(?string $format): array { if ($format !== 'json_schema') { return []; } return [ Map::class => TRUE, ]; } ``` (and analogously for `ContextDefinitionInterface::class` in `ContextDefinitionNormalizer`). A patch is available — happy to open an MR. ### Drupal version 11.2.x (also affects 10.3+) ### Tool module version 1.0.0-alpha9 (also present in 1.0.0-beta1 and 1.0.x-dev) ### AI usage (if applicable) - [x] **AI Assisted Issue:** This issue was generated with AI assistance, but was reviewed and refined by the creator. - [ ] **AI Assisted Code:** This code was mainly generated by a human, with AI autocompleting or parts AI generated, but under full human supervision. - [ ] **AI Generated Code:** This code was mainly generated by an AI with human guidance, and reviewed, tested, and refined by a human. - [ ] **Vibe Coded:** This code was generated by an AI and has only been functionally tested.
issue