justblackbird / jms-serializer-strict-json
Provide strict JSON deserialization
Installs: 10 418
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- jms/serializer: ^1.0
Requires (Dev)
- phpunit/phpunit: ^5.6
- squizlabs/php_codesniffer: ^2.8
This package is not auto-updated.
Last update: 2024-11-19 07:52:01 UTC
README
Deserialize JSON using strict types validation
Installation
Run in the command line:
composer require justblackbird/jms-serializer-strict-json
Usage
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.
License
Apache 2.0 (c) Dmitriy Simushev