PHPackages                             good-php/serialization - 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. good-php/serialization

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

good-php/serialization
======================

Extendable reflection-based serializer with support for JSON and PHP primitive formats

v2.0.0(10mo ago)320.0k↓30%21MITPHPPHP &gt;=8.2CI passing

Since Nov 3Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/good-php/serialization)[ Packagist](https://packagist.org/packages/good-php/serialization)[ RSS](/packages/good-php-serialization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (11)Versions (14)Used By (1)

Good PHP serialization
======================

[](#good-php-serialization)

The concept is similar to Moshi, a Java/Kotlin serialization library - the least effort without sacrificing customizability, support for different formats or ease of use.

This is what it can serialize and deserialize out-of-the-box:

```
/**
 * @template T1
 */
class Item
{
	/**
	 * @param BackedEnumStub[] $array
	 * @param Collection
	 * @param T1 $generic
	 * @param NestedGeneric $nested
	 */
	public function __construct(
		// Scalars
		public readonly int $int,
		public readonly float $float,
		public readonly string $string,
		public readonly bool $bool,
		// Nullable and optional values
		public readonly ?string $nullableString,
		public readonly int|null|MissingValue $optional,
		// Custom property names
		#[SerializedName('two')] public readonly string $one,
		// Backed enums
		public readonly BackedEnumStub $backedEnum,
		// Generics and nested objects
		public readonly mixed $generic,
		public readonly NestedGenerics $nestedGeneric,
		// Arrays and Illuminate Collection of any type (with generics!)
		public readonly array $array,
		public readonly Collection $collection,
		// Dates
		public readonly DateTime $dateTime,
		public readonly Carbon $carbon,
	) {}
}
```

You can then convert it into a "primitive" (scalars and arrays of scalars) or JSON:

```
$primitiveAdapter = $serializer->adapter(
	PrimitiveTypeAdapter::class,
	NamedType::wrap(Item::class, [Carbon::class])
);
// -> ['int' => 123, ...]
$primitiveAdapter->serialize(new Item(...));

$jsonAdapter = $serializer->adapter(
	JsonTypeAdapter::class,
	NamedType::wrap(Item::class, [PrimitiveType::int()])
);
// new Item(123, ...)
$jsonAdapter->deserialize('{"int": 123, ...}');
```

Documentation
-------------

[](#documentation)

Basic documentation is available in [docs/](docs). For examples, you can look at the test suite: [tests/Integration](tests/Integration).

Why this over everything else?
------------------------------

[](#why-this-over-everything-else)

There are some alternatives to this, but they usually lack one of the following:

- stupid simple internal structure: no node tree, no value/JSON wrappers, no in-repo custom reflection implementation, no PHP parsing
- doesn't rely on inheritance of serializable classes, hence allows serializing third-party classes
- parses existing PHPDoc information instead of duplicating it through attributes
- supports generic types which are quite useful for wrapper types
- allows simple extension through mappers and complex stuff through type adapters
- produces developer-friendly error messages for invalid data
- correctly handles optional (missing keys) and `null` values as separate concerns
- simple to extend with additional formats

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance54

Moderate activity, may be stable

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 82.4% 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

Every ~77 days

Recently: every ~107 days

Total

9

Last Release

305d ago

Major Versions

v1.2.0 → v2.0.02025-07-17

PHP version history (2 changes)v1.0.0-alpha.1PHP &gt;=8.1

v1.0.0-alpha.3PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10583125?v=4)[Oleksandr Prypkhan](/maintainers/autaut03)[@autaut03](https://github.com/autaut03)

---

Top Contributors

[![autaut03](https://avatars.githubusercontent.com/u/10583125?v=4)](https://github.com/autaut03 "autaut03 (42 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (9 commits)")

---

Tags

meta-programmingphpserialization

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/good-php-serialization/health.svg)

```
[![Health](https://phpackages.com/badges/good-php-serialization/health.svg)](https://phpackages.com/packages/good-php-serialization)
```

###  Alternatives

[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k14.6M107](/packages/spatie-laravel-sitemap)[ultrono/laravel-sitemap

Sitemap generator for Laravel 11, 12 and 13

36412.6k6](/packages/ultrono-laravel-sitemap)[mischasigtermans/laravel-toon

Token-Optimized Object Notation encoder/decoder for Laravel with intelligent nested object handling

13113.1k](/packages/mischasigtermans-laravel-toon)[dniccum/nova-documentation

A Laravel Nova tool that allows you to add markdown-based documentation to your administrator's dashboard.

37116.4k](/packages/dniccum-nova-documentation)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)

PHPackages © 2026

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