DateTimeZoneNormalizer example



        $extractor = new PropertyInfoExtractor([][new PhpDocExtractor()new ReflectionExtractor()]);

        $serializer = new Serializer(
            [
                new ArrayDenormalizer(),
                new DateTimeNormalizer(),
                new DateTimeZoneNormalizer(),
                new DataUriNormalizer(),
                new UidNormalizer(),
                new ObjectNormalizer($classMetadataFactory, null, null, $extractor$classMetadataFactory ? new ClassDiscriminatorFromClassMetadata($classMetadataFactory) : null),
            ],
            ['json' => new JsonEncoder()]
        );

        try {
            $serializer->deserialize($json, Php74Full::class, 'json', [
                DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
            ]);

            
use Symfony\Component\Serializer\Normalizer\DateTimeZoneNormalizer;

/** * @author Jérôme Desjardins <jewome62@gmail.com> */
class DateTimeZoneNormalizerTest extends TestCase
{
    private DateTimeZoneNormalizer $normalizer;

    protected function setUp(): void
    {
        $this->normalizer = new DateTimeZoneNormalizer();
    }

    public function testSupportsNormalization()
    {
        $this->assertTrue($this->normalizer->supportsNormalization(new \DateTimeZone('UTC')));
        $this->assertFalse($this->normalizer->supportsNormalization(new \DateTimeImmutable()));
        $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
    }

    public function testNormalize()
    {
        
Home | Imprint | This part of the site doesn't use cookies.