Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Strong Serializer

Strong Serializer Laravel Package

alexacrm/strong-serializer

Laravel/PHP utility for robust object/array serialization with strong typing and predictable output. Helps convert data structures for APIs, storage, or transport with configurable serializers and safer handling of nested values.

View on GitHub
Deep Wiki
Context7

Converts generic objects to strongly-typed objects and vice-versa.

Frequently asked questions about Strong Serializer
How do I install and configure alexacrm/strong-serializer in Laravel?
Run `composer require alexacrm/strong-serializer`, then register the service provider in `config/app.php`. Bind the serializer to Laravel’s container in a provider’s `boot()` method. Use attributes like `#[Serialize]` and `#[Deserialize]` on your classes for automatic handling.
Does this package work with Laravel API Resources?
Yes, replace `toArray()` in your API Resources with the serializer’s `serialize()` method. It enforces type safety while maintaining compatibility with Laravel’s response formatting. Example: `return Serializer::serialize($this->resource);`.
What Laravel versions and PHP versions are supported?
The package requires **PHP 8.0+** (for named arguments and attributes) and is tested with **Laravel 8+**. Check `composer.json` for exact constraints, but avoid mixing with older Laravel versions that lack attribute support.
How does it handle nested objects or circular references?
Use the `depth` parameter in `serialize()` to limit recursion. For circular references, register a custom resolver or configure the serializer to throw exceptions. Example: `Serializer::serialize($object, ['depth' => 5])`.
Can I use this for database storage (e.g., Eloquent model attributes)?
Yes, extend Eloquent models with `HasAttributes` or use model observers to auto-serialize data before saving. For casting, override `getAttributes()` to return serialized arrays. Avoid direct JSON serialization in migrations.
What if my data contains unsupported types (e.g., Carbon, UUID)?
Register custom resolvers via `Serializer::addResolver()`. Example: `Serializer::addResolver(new CarbonResolver())`. The package ships with basic support for `DateTime` and `Collection`, but extensions are needed for third-party types.
How does performance compare to Laravel’s native casting or spatie/array-to-object?
Reflection-based serialization adds overhead, so benchmark against alternatives. For high-throughput APIs, cache serialized results or use `spatie/array-to-object` for simpler cases. Test with tools like Blackfire to compare latency.
Will this break existing code if types don’t match (e.g., null vs. string)?
Yes, strict typing may fail if data doesn’t align with class properties. Mitigate by using fallback types (e.g., `?string` instead of `string`) or implementing a `FallbackResolver` to handle ambiguous cases gracefully.
Can I integrate this with Laravel Form Request validation?
Absolutely. Use the serializer to deserialize incoming request data into strongly typed objects, then validate the object properties. Example: `Serializer::deserialize($request->all(), MyRequestClass::class)`. Combine with Laravel’s validation rules for robust input handling.
What’s the best approach to migrate from manual JSON serialization to this package?
Start with non-critical endpoints (e.g., admin panels) to test performance and type safety. Replace `json_encode()` with `Serializer::serialize()` incrementally. Use a decorator pattern to wrap the serializer and log deprecation warnings during the transition.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor