mennovanhout/laravel-jms

Adds jms serializer to Laravel

0.3.0 2022-09-20 12:25 UTC

This package is auto-updated.

Last update: 2024-06-20 16:21:28 UTC


README

Laravel JMS

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