motivo-zwolle/laravel-jms

Adds jms serializer to Laravel

0.2.7 2020-06-22 14:16 UTC

This package is auto-updated.

Last update: 2024-04-22 22:38:31 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