dropelikeit/laravel-jms-serializer

Integration JMS Serializer in Laravel / Lumen

v6.0.1 2024-05-20 13:58 UTC

This package is auto-updated.

Last update: 2024-11-20 19:16:36 UTC


README

Gitworkflow Coverage Status Monthly Downloads Daily Downloads Total Downloads Latest Stable Version Total Downloads License composer.lock Mutation testing badge

JMS Serializer for Laravel

This package integrates the JMS serializer into Laravel.

JMS-Serializer: https://github.com/schmittjoh/serializer

You are also welcome to use the Issue Tracker to set bugs, improvements or upgrade requests.

Installation

composer require dropelikeit/laravel-jms-serializer

Support note

How to use

Laravel uses Package Auto-Discovery, so you do not need to add the service provider manually.

For example, to use the JMS serializer in a controller, add the ResponseFactory in the constructor.

    <?php 
    namespace App\Http\Controller;

    use Dropelikeit\LaravelJmsSerializer\Http\Responses\ResponseFactory;
    use Symfony\Component\HttpFoundation\JsonResponse;

    final class ExampleController extends Controller 
    {
        public function __construct(private ResponseFactory $responseFactory) {}

        public function myAction(): JsonResponse
        {
            $myDataObjectWithSerializerAnnotations = new Object('some data');
            return $this->responseFactory->create($myDataObjectWithSerializerAnnotations);
        }
    }

Publish the Serializer Config with the command

    php artisan vendor:publish

After that you will see a config file in your config folder named "laravel-jms-serializer.php".

Upgrade

If you are upgrading this package from a version earlier than v4.0, see this upgrade file.

Documentation