Deserialize JSON using strict types validation
Run in the command line:
composer require justblackbird/jms-serializer-strict-json
Use the StrictJsonDeserializationVisitor
from the package instead of JMSSerializer built in JsonDeserializationVisitor
.
For example, if you use the following code to instantiate JMS serializer:
use JMS\Serializer\SerializerBuilder;
$serializer = SerializerBuilder::create()->build();
You should change it to something like:
use JMS\Serializer\Naming\CamelCaseNamingStrategy;
use JMS\Serializer\Naming\SerializedNameAnnotationStrategy;
use JMS\Serializer\SerializerBuilder;
use JustBlackBird\JmsSerializerStrictJson\StrictJsonDeserializationVisitor;
$naming_strategy = new SerializedNameAnnotationStrategy(new CamelCaseNamingStrategy());
$serializer = SerializerBuilder::create()
->setPropertyNamingStrategy($naming_strategy)
->setDeserializationVisitor('json', new StrictJsonDeserializationVisitor($naming_strategy))
->build();
Then use the serializer as you used to.
Apache 2.0 (c) Dmitriy Simushev