Skip to content

CodersLab-core/jms-serializer-strict-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JMS Serializer Strict JSON Build Status

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

About

Provide strict JSON deserialization with JMS Serializer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%