Fix bug with non serializing recursive departure

This commit is contained in:
Kacper Donat 2020-03-21 15:41:49 +01:00
parent cde6507197
commit 7279f2096e
5 changed files with 32 additions and 3 deletions

View File

@ -1,4 +1,8 @@
jms_serializer: jms_serializer:
default_context:
serialization:
serialize_null: true
visitors: visitors:
xml_serialization: xml_serialization:
format_output: '%kernel.debug%' format_output: '%kernel.debug%'

View File

@ -42,7 +42,7 @@ export class PickerStopComponent extends Vue {
[lines => lines.length > 2, ([first]) => `${first.symbol}`], [lines => lines.length > 2, ([first]) => `${first.symbol}`],
); );
return unique(this.stop.destinations || [], destination => destination.stop.name).map(compactLines); return unique(this.stop.destinations || [], destination => destination.stop && destination.stop.name).map(compactLines);
} }
} }

View File

@ -7,6 +7,7 @@ use App\Event\PostProcessEvent;
use App\Handler\PostProcessingHandler; use App\Handler\PostProcessingHandler;
use App\Model\Destination; use App\Model\Destination;
use App\Model\Stop; use App\Model\Stop;
use App\Service\CacheableConverter;
use App\Service\Converter; use App\Service\Converter;
use App\Service\IdUtils; use App\Service\IdUtils;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
@ -25,6 +26,11 @@ class WithDestinationsDatabaseHandler implements PostProcessingHandler
$this->em = $entityManager; $this->em = $entityManager;
$this->converter = $converter; $this->converter = $converter;
$this->id = $id; $this->id = $id;
if ($this->converter instanceof CacheableConverter) {
$this->converter = clone $this->converter;
$this->converter->flushCache();
}
} }
public function postProcess(PostProcessEvent $event) public function postProcess(PostProcessEvent $event)

View File

@ -3,8 +3,9 @@
namespace App\Service; namespace App\Service;
use Tightenco\Collect\Support\Collection; use Tightenco\Collect\Support\Collection;
use function Kadet\Functional\Predicates\instance;
class AggregateConverter implements Converter class AggregateConverter implements Converter, CacheableConverter
{ {
private $converters; private $converters;
@ -42,4 +43,22 @@ class AggregateConverter implements Converter
{ {
return clone $this->converters; return clone $this->converters;
} }
public function flushCache()
{
$this
->converters
->filter(instance(CacheableConverter::class))
->each(function (CacheableConverter $converter) {
$converter->flushCache();
})
;
}
public function __clone()
{
$this->converters = $this->converters->map(function ($object) {
return clone $object;
});
}
} }

View File

@ -23,7 +23,7 @@ final class SerializerContextFactory
public function create($subject, array $groups = ['Default']) public function create($subject, array $groups = ['Default'])
{ {
return SerializationContext::create()->setGroups($this->groups($subject, $groups)); return SerializationContext::create()->setSerializeNull(true)->setGroups($this->groups($subject, $groups));
} }
private function groups($subject, array $groups) private function groups($subject, array $groups)