TypeError in ComplexDataDefinitionNormalizer

Created on 8 October 2025, 16 days ago
Updated 13 October 2025, 11 days ago

Problem/Motivation

When using the Umami demo profile, calling the JSON:API Schema endpoint for the article content type
(/jsonapi/node/article/resource/schema) triggers a PHP TypeError in the
ComplexDataDefinitionNormalizer class of the jsonapi_schema module.

The error indicates that the normalize() method is returning a stdClass object instead of one of
the expected types (ArrayObject, array, string, int,
float, bool, or null).

This prevents the schema from being correctly generated and makes it impossible to retrieve the JSON:API schema definition for the article resource in Umami.

Steps to reproduce

  1. Install Drupal using the Umami demo profile.
  2. Enable the jsonapi and jsonapi_schema modules.
  3. Go to the endpoint: /jsonapi/node/article/resource/schema.
  4. Observe the error message:
TypeError: Drupal\jsonapi_schema\Normalizer\ComplexDataDefinitionNormalizer::normalize(): 
Return value must be of type ArrayObject|array|string|int|float|bool|null, stdClass returned 
in Drupal\jsonapi_schema\Normalizer\ComplexDataDefinitionNormalizer->normalize() (line 51 of 
modules/contrib/jsonapi_schema/src/Normalizer/ComplexDataDefinitionNormalizer.php)

Proposed resolution

Ensure that ComplexDataDefinitionNormalizer::normalize() consistently returns one of the allowed data types.
This may involve:

  • Updating the method to cast or convert stdClass results to arrays or ArrayObject instances.
  • Verifying that nested normalizers do not produce stdClass outputs.
  • Adding test coverage for resource schemas within demo profiles like Umami to detect this issue automatically.

Remaining tasks

  • Investigate where the stdClass object originates from in the normalization process.
  • Implement and test a fix ensuring type compliance.
  • Add automated tests to cover schema generation for content entities using the Umami profile.
  • Submit a patch or merge request to the jsonapi_schema project.

User interface changes

None. This issue affects the backend JSON:API schema generation only.

API changes

No API changes are expected, but the normalization process should be corrected to comply with the declared return types.

Data model changes

None. This issue is limited to schema serialization and does not modify any stored data or entity definitions.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇮🇹Italy robertoperuzzo 🇮🇹 Tezze sul Brenta, VI

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024