понедельник, 19 апреля 2021 г.

[JMSSerializer] default serialization group are ignored fix

 If your default serialization group not working (does not ignore fields which should be shown only with specific group, not Default), check that \JMS\Serializer\Exclusion\GroupsExclusionStrategy is added into \JMS\Serializer\Context at  \JMS\Serializer\GraphNavigator::accept() method.

If you are using Sylius (or standalone bundles), it occurs when \FOS\RestBundle\Serializer\JMSSerializerAdapter does not add GroupsExclusionStrategy. You can fix it with adding serialization_groups: [Default] like this:

api_building_show:

    path: /exam/{id}

    methods: [GET]

    defaults:

        _controller: app.controller.building:showAction

        _sylius:

            serialization_groups: [Default]

суббота, 17 апреля 2021 г.

[FOSRestBundle] Showing custom Exception message no working fix

 If ./config/packages/fos_rest.yaml:

fos_rest:

    exception:

        messages:

            Symfony\Component\HttpKernel\Exception\HttpException: true

for you too, you can inject this service manually like this in services.yaml:

fos_rest.exception.messages_map:

        class: FOS\RestBundle\Util\ExceptionValueMap

        public: false

        arguments:

            - { Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException: true }

thanks to https://github.com/FriendsOfSymfony/FOSRestBundle/issues/1522 

четверг, 15 апреля 2021 г.

[FosRestBundle] [JmsSerializerBundle] how to show datetime in correct timezone

If your date fields looks like "2021-04-08T00:00:00+00:00", instead of your preferred timezone, set correct timezone in your cli/fpm php.ini:

[Date]

date.timezone = "Europe/Riga"