Follow-up to #3627338: Serializer::getJsonSchema() throws a TypeError when passed a class name. JsonSchemaProviderSerializerInterface::getJsonSchema() declares mixed $object, but only an object returns a schema. A class name throws a TypeError about the return type. Assuming #3627338: Serializer::getJsonSchema() throws a TypeError when passed a class name gets committed, passing anything other than an object is deprecated in Drupal 12.1.0.

In Drupal 13.0.0:

  • Type $object as object on JsonSchemaProviderSerializerInterface::getJsonSchema() and JsonSchemaProviderSerializerTrait::getJsonSchema().
  • Remove the !is_object() check and its trigger_error() from JsonSchemaProviderSerializerTrait::getJsonSchema().
  • Remove SerializationTest::testGetJsonSchemaArrayDeprecation().
  • Remove the @todo from the interface docblock.
  • Remove the is_string($object) branch from JSON:API's FieldItemNormalizer::getNormalizationSchema() (#2).

Comments

dries created an issue. See original summary.

mglaman’s picture

One more item for the scope here. FieldItemNormalizer::getNormalizationSchema() in JSON:API still has a branch for class names:

if (is_string($object)) {
  return ['$comment' => 'No detailed schema available.'] + $schema;
}

Once getJsonSchema() only accepts objects, nothing reaches this branch. Remove it and let the assert($object instanceof FieldItemInterface) below it do the work.

Also, #3627338 ended up deprecating any non-object, not only arrays. The summary should say that, and the !is_object() check with its trigger_error() in JsonSchemaProviderSerializerTrait::getJsonSchema() goes away along with the test.

Generated with the help of an LLM.

dries’s picture

Issue summary: View changes

Updated the issue summary per #2 and the latest changes in #3627338.