class JsonSerializableNormalizer
A normalizer that uses an objects own JsonSerializable implementation.
@author Fred Cox <mcfedr@gmail.com>
Hierarchy
- class \Symfony\Component\Serializer\Normalizer\AbstractNormalizer implements \Symfony\Component\Serializer\Normalizer\NormalizerInterface, \Symfony\Component\Serializer\Normalizer\DenormalizerInterface, \Symfony\Component\Serializer\SerializerAwareInterface uses \Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait, \Symfony\Component\Serializer\SerializerAwareTrait
- class \Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer extends \Symfony\Component\Serializer\Normalizer\AbstractNormalizer
Expanded class hierarchy of JsonSerializableNormalizer
File
-
vendor/
symfony/ serializer/ Normalizer/ JsonSerializableNormalizer.php, line 22
Namespace
Symfony\Component\Serializer\NormalizerView source
final class JsonSerializableNormalizer extends AbstractNormalizer {
public function normalize(mixed $object, ?string $format = null, array $context = []) : array|string|int|float|bool|\ArrayObject|null {
if ($this->isCircularReference($object, $context)) {
return $this->handleCircularReference($object, $format, $context);
}
if (!$object instanceof \JsonSerializable) {
throw new InvalidArgumentException(\sprintf('The object must implement "%s".', \JsonSerializable::class));
}
if (!$this->serializer instanceof NormalizerInterface) {
throw new LogicException('Cannot normalize object because injected serializer is not a normalizer.');
}
return $this->serializer
->normalize($object->jsonSerialize(), $format, $context);
}
public function getSupportedTypes(?string $format) : array {
return [
\JsonSerializable::class => true,
];
}
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []) : bool {
return $data instanceof \JsonSerializable;
}
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []) : bool {
return false;
}
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []) : mixed {
throw new LogicException(\sprintf('Cannot denormalize with "%s".', \JsonSerializable::class));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
AbstractNormalizer::$defaultContext | protected | property | |||
AbstractNormalizer::ALLOW_EXTRA_ATTRIBUTES | public | constant | If ATTRIBUTES are specified, and the source has fields that are not part of that list, either ignore those attributes (true) or throw an ExtraAttributesException (false). |
||
AbstractNormalizer::applyCallbacks | final protected | function | |||
AbstractNormalizer::applyFilterBool | final protected | function | |||
AbstractNormalizer::ATTRIBUTES | public | constant | Limit (de)normalize to the specified names. | ||
AbstractNormalizer::CALLBACKS | public | constant | Hashmap of field name => callable to (de)normalize this field. | ||
AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER | public | constant | Handler to call when a circular reference has been detected. | ||
AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT | public | constant | How many loops of circular reference to allow while normalizing. | ||
AbstractNormalizer::CIRCULAR_REFERENCE_LIMIT_COUNTERS | protected | constant | @internal | ||
AbstractNormalizer::createChildContext | protected | function | @internal | 1 | |
AbstractNormalizer::DEFAULT_CONSTRUCTOR_ARGUMENTS | public | constant | Hashmap of default values for constructor arguments. | ||
AbstractNormalizer::denormalizeParameter | protected | function | @internal | 1 | |
AbstractNormalizer::FILTER_BOOL | public | constant | Flag to control whether a non-boolean value should be filtered using the filter_var function with the {\FILTER_VALIDATE_BOOL filter before casting it to a boolean. |
||
AbstractNormalizer::getAllowedAttributes | protected | function | Gets attributes to normalize using groups. | 1 | |
AbstractNormalizer::getAttributeDenormalizationContext | protected | function | Computes the denormalization context merged with current one. Metadata always wins over global context, as more specific. | ||
AbstractNormalizer::getAttributeMetadata | protected | function | @internal | ||
AbstractNormalizer::getAttributeNormalizationContext | protected | function | Computes the normalization context merged with current one. Metadata always wins over global context, as more specific. | ||
AbstractNormalizer::getConstructor | protected | function | Returns the method to use to construct an object. This method must be either the object constructor or static. |
||
AbstractNormalizer::getGroups | protected | function | |||
AbstractNormalizer::GROUPS | public | constant | Only (de)normalize attributes that are in the specified groups. | ||
AbstractNormalizer::handleCircularReference | protected | function | Handles a circular reference. | ||
AbstractNormalizer::IGNORED_ATTRIBUTES | public | constant | Skip the specified attributes when normalizing an object tree. | ||
AbstractNormalizer::instantiateObject | protected | function | Instantiates an object using constructor parameters when needed. | 1 | |
AbstractNormalizer::isAllowedAttribute | protected | function | Is this attribute allowed? | 3 | |
AbstractNormalizer::isCircularReference | protected | function | Detects if the configured circular reference limit is reached. | ||
AbstractNormalizer::OBJECT_TO_POPULATE | public | constant | Instead of creating a new instance of an object, update the specified object. | ||
AbstractNormalizer::prepareForDenormalization | protected | function | Normalizes the given data to an array. It's particularly useful during the denormalization process. |
||
AbstractNormalizer::REQUIRE_ALL_PROPERTIES | public | constant | Require all properties to be listed in the input instead of falling back to null for nullable ones. |
||
AbstractNormalizer::validateCallbackContext | final protected | function | Validate callbacks set in context. | ||
AbstractNormalizer::__construct | public | function | Sets the {@link ClassMetadataFactoryInterface} to use. | 1 | |
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS | public | constant | |||
JsonSerializableNormalizer::denormalize | public | function | Denormalizes data back into an object of the given class. | Overrides DenormalizerInterface::denormalize | |
JsonSerializableNormalizer::getSupportedTypes | public | function | Returns the types potentially supported by this normalizer. | Overrides NormalizerInterface::getSupportedTypes | |
JsonSerializableNormalizer::normalize | public | function | Normalizes data into a set of arrays/scalars. | Overrides NormalizerInterface::normalize | |
JsonSerializableNormalizer::supportsDenormalization | public | function | Checks whether the given class is supported for denormalization by this normalizer. | Overrides DenormalizerInterface::supportsDenormalization | |
JsonSerializableNormalizer::supportsNormalization | public | function | Checks whether the given class is supported for normalization by this normalizer. | Overrides NormalizerInterface::supportsNormalization | |
ObjectToPopulateTrait::extractObjectToPopulate | protected | function | Extract the `object_to_populate` field from the context if it exists and is an instance of the provided $class. |
||
SerializerAwareTrait::$serializer | protected | property | |||
SerializerAwareTrait::setSerializer | public | function |