StringNormalizer.php in Drupal 9
File
core/modules/jsonapi/tests/modules/jsonapi_test_data_type/src/Normalizer/StringNormalizer.php
View source
<?php
namespace Drupal\jsonapi_test_data_type\Normalizer;
use Drupal\Core\TypedData\Plugin\DataType\StringData;
use Drupal\serialization\Normalizer\NormalizerBase;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
class StringNormalizer extends NormalizerBase implements DenormalizerInterface {
protected $supportedInterfaceOrClass = StringData::class;
public function normalize($object, $format = NULL, array $context = []) {
return str_replace('super', 'NOT', $object
->getValue());
}
public function denormalize($data, $class, $format = NULL, array $context = []) {
return str_replace('NOT', 'super', $data);
}
}
Classes
Name |
Description |
StringNormalizer |
Normalizes string data weirdly: replaces 'super' with 'NOT' and vice versa. |