New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

good-php/serialization

Extendable reflection-based serializer with support for JSON and PHP primitive formats
27,924 3

Larablocks Analysis

good-php/serialization works with Laravel 10, 11 and 12 (latest release v2.0.0, Jul 17, 2025).

Recommendation checks

Use with care

Use with care: meets 0 of 4 checks.

  • Latest release doesn't support Laravel 13, the current version
  • No release in the last 12 months (last: Jul 17, 2025)
  • 1,479 downloads a month (needs 10,000)
  • 3 GitHub stars (needs 100)

State

Quiet
  • Last stable release: Jul 17, 2025.
  • No releases in the last 12 months.
  • First released: Nov 3, 2023.
  • Monthly downloads: 1,479.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Nov 30, 2026.

Install
composer require good-php/serialization
Latest Version:v2.0.0
PHP:>=8.2
Laravel:10 · 11 · 12
License:MIT
Last Updated:Jul 17, 2025
Links: GitHub  ·  Packagist
Maintainer: autaut03

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<int, T1>
	 * @param T1 $generic
	 * @param NestedGeneric<int, T1> $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

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

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

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

670,032,257 9,703
laravel/framework

The Laravel Framework.

640,572,096 35,338
laravel/tinker

Powerful REPL for the Laravel framework.

546,909,908 7,440
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

465,816,364 607
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

431,187,642 4,660

Version History

Version Released PHP Laravel License
v2.0.0 >=8.2 ^10.0 || ^11.0 || ^12.0 MIT
v1.2.0 >=8.2 ^10.0 || ^11.0 MIT
v1.1.1 >=8.2 MIT
v1.1.0 >=8.2 MIT
v1.0.0 >=8.2 MIT
Pre-releases (4)
Version Released PHP License
v1.0.0-alpha.4 >=8.2 MIT
v1.0.0-alpha.3 >=8.2 MIT
v1.0.0-alpha.2 >=8.1 MIT
v1.0.0-alpha.1 >=8.1 MIT