motivo-zwolle / laravel-jms
Adds jms serializer to Laravel
0.2.7
2020-06-22 14:16 UTC
Requires
- doctrine/cache: ^1.10
- jms/serializer: ^3.5
This package is auto-updated.
Last update: 2024-10-22 23:36:36 UTC
README
More info coming soon
Installation
composer require mennovanhout/laravel-jms
Usage
$serializer = app(Serializer::class);
Example
JSON
{ "title": "Hello World!" }
DTO
use JMS\Serializer\Annotation as Serializer; class PaymentDTO { /** * @Serializer\SerializedName("title") * @Serializer\Type("string") * * @var string */ private $title; /** * @return string */ public function getTitle(): string { return $this->title; } }
Deserialize
$serializer = app(Serializer::class); /** @var PaymentDTO */ $paymentDTO = $serializer->deserialize($json, PaymentDTO::class, 'json');
Serialize
$serializer = app(Serializer::class); $json = $serializer->serialize($paymentDTO, 'json');
More info
Annotations: https://jmsyst.com/libs/serializer/master/reference/annotations