JsonSchemaProviderSerializerTrait.php

Namespace

Drupal\serialization\Serializer

File

core/modules/serialization/src/Serializer/JsonSchemaProviderSerializerTrait.php

View source
<?php

declare (strict_types=1);
namespace Drupal\serialization\Serializer;

use Drupal\serialization\Normalizer\SchematicNormalizerFallbackTrait;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;

/**
 * Trait for normalizing the JSON schema.
 */
trait JsonSchemaProviderSerializerTrait {
  use SchematicNormalizerFallbackTrait;
  
  /**
   * {@inheritdoc}
   */
  public function getJsonSchema(mixed $object, array $context) : array {
    try {
      $normalizer_schema = $this->normalize($object, 'json_schema', $context);
    } catch (NotNormalizableValueException) {
      $normalizer_schema = [
        '$comment' => static::generateNoSchemaAvailableMessage($object),
      ];
    }
    return $normalizer_schema;
  }

}

Traits

Title Deprecated Summary
JsonSchemaProviderSerializerTrait Trait for normalizing the JSON schema.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.