PHPackages                             tcds-io/php-jackson-symfony - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. tcds-io/php-jackson-symfony

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

tcds-io/php-jackson-symfony
===========================

A Symfony bundle to inject and respond serializable objects in controllers

1.0.0(3mo ago)00MITPHPPHP &gt;=8.4CI passing

Since Jan 14Pushed 3mo agoCompare

[ Source](https://github.com/tcds-io/php-jackson-symfony)[ Packagist](https://packagist.org/packages/tcds-io/php-jackson-symfony)[ RSS](/packages/tcds-io-php-jackson-symfony/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

PHP Jackson for Symfony
=======================

[](#php-jackson-for-symfony)

Symfony integration for [tcds-io/php-jackson](https://github.com/tcds-io/php-jackson), a type-safe object mapper inspired by Jackson (Java).

This package lets you:

- Inject **typed objects** (and collections) directly into controllers and route callables
- Deserialize from JSON body, query params, form data, and route params
- Automatically serialize your return values back to JSON using PHP-Jackson

---

🚀 Installation
--------------

[](#-installation)

```
composer require tcds-io/php-jackson-symfony
```

Then create the configuration file:

```
bin/console jackson:configure # config/jackson.php
```

---

⚙️ How it works
---------------

[](#️-how-it-works)

1. The plugin inspects your **method parameter types** and **PHPDoc generics**.
2. It builds those objects from:
    - Route params (`{id}`)
    - Query / form data
    - JSON body
3. Your return value is serialized automatically using PHP‑Jackson.

---

🧩 Controller-based injection &amp; response
-------------------------------------------

[](#-controller-based-injection--response)

```
// Your controller
class FooBarController
{
    /**
     * @param list $items
     * @return list
     */
    #[Route('/controller', methods: ['POST'])]
    public function list(array $items): array
    {
        return $items;
    }

    #[Route('/controller/{id}', methods: ['POST'])]
    public function read(int $id, Foo $foo): Foo
    {
        return new Foo(
            id: $id,
            a: $foo->a,
            b: $foo->b,
            type: $foo->type,
        );
    }

    #[Route('/invoices/{id}', methods: ['POST'])]
    public function invoices(InvoiceQuery $query): InvoiceQuery
    {
        return $query;
    }
}

// config/jackson.php
/**
 * @returns array{
 *     mappers: array,
 *     params?: callable(Container $container, ObjectMapper $mapper): array
 * }
 */
return [
    'mappers' => [
        App\Domain\Foo::class => [],
        App\Queries\InvoiceQuery::class => [],
    ],
    'params' => function (Container $container) {
        $authService = $container->get(AuthTokenService::class);

        return $authService->getClaims();
    },
];
```

---

🛠 Configuring Serializable Objects
----------------------------------

[](#-configuring-serializable-objects)

To enable automatic request → object → response mapping, register your serializable classes in:

```
config/jackson.php

```

### Example configuration

[](#example-configuration)

```
return [
    'mappers' => [
        // Simple automatic serialization
        Address::class => [],

        // Custom readers and writers
        Foo::class => [
            'reader' => fn(array $data) => new Foo($data['a'], $data['b']),
            'writer' => fn(Foo $foo) => ['a' => $foo->a, 'b' => $foo->b],
        ],

        // Use Laravel's Auth system to inject the authenticated user
        User::class => [
            // Any controller that includes `User $user` will automatically receive `Auth::user()`.
            'reader' => fn () => Auth::user(),

            // Optional: control what is exposed in API responses.
            // Responses containing a `User` instance will use your custom `writer` output.
            'writer' => fn (User $user) => [
                'id' => $user->id,
                'name' => $user->name,
                // 'email' => $user->email, // exclude sensitive fields
            ],
        ],

        // Other classes:
        // - Unregistered classes cannot be serialized or deserialized (security-by-default).
    ],
    'params' => function (Container $container, ObjectMapper $mapper) {
        return [
            // Any custom data you want to be injected into serializable classes
        ];
    },
];
```

---

🧪 Error handling
----------------

[](#-error-handling)

If parsing fails, php-jackson-symfony converts php-jackson `UnableToParseValue` into `400 Bad Request` HTTP error responses, ex:

```
{
  "message": "Unable to parse value at .type",
  "expected": ["AAA", "BBB"],
  "given": "string"
}
```

---

📦 Related packages
------------------

[](#-related-packages)

- Core mapper:
- Laravel integration:
- Guzzle integration:

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance83

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

115d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8ac1821d71c0ddddcc3494a165dc40cfa3e759a467d8a00956ceeae4b833bb3?d=identicon)[thiagocordeiro](/maintainers/thiagocordeiro)

---

Top Contributors

[![thiagocordeiro](https://avatars.githubusercontent.com/u/1073649?v=4)](https://github.com/thiagocordeiro "thiagocordeiro (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tcds-io-php-jackson-symfony/health.svg)

```
[![Health](https://phpackages.com/badges/tcds-io-php-jackson-symfony/health.svg)](https://phpackages.com/packages/tcds-io-php-jackson-symfony)
```

###  Alternatives

[presta/sitemap-bundle

A Symfony bundle that provides tools to build your application sitemap.

3929.4M28](/packages/presta-sitemap-bundle)[symfony-bundles/json-request-bundle

Symfony JsonRequest Bundle

501.6M6](/packages/symfony-bundles-json-request-bundle)[eprofos/user-agent-analyzer

A powerful Symfony bundle for user-agent analysis. It provides accurate detection of operating systems (Windows, MacOS, Linux, iOS, Android...), browsers (Chrome, Firefox, Safari...), and device types (Desktop, Mobile, Tablet, TV...). Supports specific version detection and includes advanced handling of special cases like WebViews and compatibility modes. Features comprehensive logging and detailed analysis results.

182.3k](/packages/eprofos-user-agent-analyzer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
