Weave 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

Json Serializer Laravel Package

zumba/json-serializer

A PHP library that serializes variables and objects to JSON and restores them, including binary data, nested objects, recursion, and closures. Requires PHP 7.2+; never unserialize untrusted input.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Core Use Case Alignment (Confirmed)

    • Parent Class Private Property Support (PR #71): Directly resolves Laravel’s inheritance complexity (e.g., Eloquent models extending HasAuditLog or SoftDeletes with private/protected parent properties). Eliminates manual accessor overrides, aligning with Laravel’s composition-over-inheritance patterns while accommodating legacy codebases.
    • Typed Property Resilience (PR #68): Critical for Laravel 10/11’s PHP 8.0+ typed properties (e.g., protected Carbon\Carbon $created_at). Prevents fatal errors during serialization/deserialization, reducing friction for modern Laravel APIs and event-driven architectures (e.g., Horizon jobs).
    • Security-First Design (PR #70): SECURITY.md introduces unserialize input validation, addressing a critical gap in Laravel’s native tools. Complements Illuminate\Validation and GraphQL/API payload use cases where serialized data is consumed from untrusted sources (e.g., microservices or legacy systems).
    • Opis/Closure v4 (PR #69): Ensures compatibility with modern PHP tooling, reducing integration risks for Laravel projects using Opis-based testing or runtime reflection (e.g., Laravel Scout drivers).
    • PHP 8.5 Forward Compatibility (PR #78, new in 3.2.5): Resolves SplObjectStorage::contains()/attach() and ReflectionProperty::setAccessible() deprecations. This is architecturally neutral but strategically material — it removes a known blocker for teams sequencing a PHP 8.5 / Laravel 12+ upgrade, and it means the package’s reflection internals are being tracked against the PHP runtime roadmap rather than lagging it.
  • Laravel Ecosystem Synergy (Expanded)

    • Eloquent Model Optimization: Native support for typed properties and parent class hierarchies eliminates boilerplate for complex models (e.g., App\Models\User extending App\Models\Concerns\HasMetadata). Reduces reliance on custom JsonSerializable implementations.
    • API Payload Safety: Bidirectional serialization (serialize/deserialize) is now security-hardened, making it suitable for GraphQL APIs, event queues, and cached data (e.g., Redis::remember() with typed properties).
    • Legacy Migration: Resolves serialization failures in pre-PHP 8.0 Laravel apps where uninitialized typed properties or parent class privates caused fatal errors. Enables zero-downtime upgrades to modern PHP versions. Caveat (new): the legacy path is only viable on 3.2.5+ — 3.2.4 regressed PHP < 7.4 (see Technical Risk).
  • Alternatives Revisited (Unchanged)

    • Laravel Native Tools: Still lacks unserialize support and parent class property access, making this package a strict upgrade for advanced use cases.
    • Symfony Serializer: Overkill for Laravel’s simplicity; this package offers Laravel-specific optimizations (e.g., Eloquent model awareness).
    • spatie/array-to-object: No support for typed properties or security-hardened unserialization.

Integration Feasibility

  • Laravel Compatibility (Confirmed)

    • Pros:
      • PHP 8.0+ Typed Properties: Fully compatible with Laravel 10/11’s strict_types=1 and typed Eloquent fields (e.g., protected int $status).
      • Parent Class Access: Eliminates manual getAttribute() overrides for private parent properties, reducing technical debt in legacy codebases.
      • Security Controls: SECURITY.md aligns with Laravel’s input validation best practices (e.g., Illuminate\Validation\Rules\ValidatedData).
      • Broadened Runtime Matrix (3.2.5): CI now exercises PHP 7.2 → 8.5 on every supported version. This upgrades our PHP support conclusion from “8.0+ confirmed” to a verified 7.2–8.5 matrix, which covers legacy Laravel 6/7/8 estates and forward-looking Laravel 12-era deployments from a single dependency constraint.
    • Cons:
      • No Laravel Facade: Requires manual service provider binding (mitigated via updated Integration Approach).
      • Middleware Conflicts: Custom JSON serialization middleware may clash with Laravel’s App\Exceptions\Handler if both use json_encode(). Mitigation: Use middleware only for API routes and avoid overriding Handler.
      • Version-Sensitive Legacy Support (3.2.5): The 7.2/7.3 path is only safe on 3.2.5+. Any team that pinned 3.2.4 for legacy compatibility is exposed to a fatal ReflectionProperty::isInitialized() error. Constraint must be ^3.2.5 or tighter, not ^3.2.
  • PHP Version Support (Updated)

    • Confirmed: PHP 7.2 – 8.5, validated in CI per release (7.2/7.3 via the 3.2.5 regression fix; 8.5 via deprecation fixes). Critical for Laravel 10/11 (8.1+) and unblocks the 8.5 upgrade path. Opis/Closure v4 (PR #69) ensures no regressions with modern PHP tooling.
  • Testing Overhead (Updated)

    • New Test Cases Required:
      1. Parent Class Private Properties: Test with Eloquent models extending BaseModel with private fields (e.g., App\Models\User → App\Models\Concerns\HasAuditLog).
      2. Uninitialized Typed Properties: Validate with PHP 8.0+ models (e.g., protected ?string $metadata).
      3. Security Validation: Audit unserialize() usage in request parsing and cached data (e.g., Redis::remember()).
      4. Performance Regression: Compare against native json_encode() for 10K+ objects with typed properties.
      5. Opis/Closure v4: Test with Laravel Pint, PHPStan, and Psalm to ensure no tooling conflicts.
      6. PHP 8.5 Deprecation Gate (new): Run CI with E_ALL on PHP 8.5 and fail on deprecations — specifically SplObjectStorage and ReflectionProperty::setAccessible() paths, which are runtime-sensitive and were only caught upstream after release.
      7. Minimum-PHP Smoke Test (new): Add a PHP 7.2/7.3 job if any legacy Laravel app remains in the estate. The 3.2.4 regression was invisible on 8.x and only surfaced on the floor of the matrix.

Technical Risk

Risk Area Severity Mitigation Strategy Update from 3.2.4
Breaking Changes None 3.2.5 is a patch release; no API changes. Pin ^3.2.5 in composer.json — do not allow 3.2.4. Updated (pin floor)
Release Quality / Regression Medium 3.2.4 introduced a fatal error on PHP < 7.4 (ReflectionProperty::isInitialized()), repaired in 3.2.5. Treat patch releases as reviewable: enable Dependabot/Renovate with a staging soak before merge; require CI on the floor and ceiling of our PHP matrix. New
Performance Medium Benchmark parent class property access overhead vs. native json_encode(). Focus on large object graphs. 3.2.5 changes reflection call paths (deprecation fixes) — re-run benchmarks, do not assume parity with 3.2.4. Updated (re-benchmark)
Complexity Bloat Low Restrict to API payloads, legacy migration, and event-driven architectures. N/A
Maintenance Burden Low MIT license; fork if upstream stalls. Upstream responsiveness is evidenced (3 issues closed, community PR merged within the 3.2.5 cycle). Upgraded (signal positive)
Security High Unchanged and still the dominant risk. Enforce strict mode for unserialize(); restrict to whitelisted trusted sources (e.g., internal APIs). Audit cached data (Redis, file cache) and event payloads. 3.2.5 does not alter the security posture. Unchanged
Typed Property Support Low Test with PHP 8.0+ Eloquent models and nullable types. N/A
Parent Class Access Medium Validate no conflicts with Laravel’s getAttribute(). Test with deep inheritance chains. N/A
Opis/Closure v4 Low Monitor for tooling conflicts (Pint, PHPStan) on PHP 8.5. Updated (8.5)
PHP Version Drift Low Matrix verified 7.2–8.5 in CI each release. Re-check matrix coverage per release; floor support can silently regress (as 3.2.4 demonstrated). Updated
PHP 8.5 Deprecations Low Resolved in 3.2.5 (SplObjectStorage, ReflectionProperty::setAccessible()). Removes a known Laravel 12+/PHP 8.5 upgrade blocker. Resolved

Key Questions (Updated)

  1. How does parent class property access interact with Laravel’s accessors?
    • Example: If App\Models\User extends App\Models\BaseModel with private $apiToken, will the serializer bypass getAttribute('api_token')?
    • Follow-up: Test with method overriding (e.g., getApiTokenAttribute()).
  2. What’s the performance impact of typed property handling in large object graphs?
    • Benchmark against native json_encode() for 10K Eloquent models with typed properties.
    • Focus: Measure memory usage and CPU overhead in API batch processing.
    • New: Baseline must be re-taken on 3.2.5, since the 3.2.5 reflection changes alter call paths versus 3.2.4.
  3. How should unserialize() be secured in Laravel?
    • Should we whitelist trusted sources (e.g., internal microservices) or disable entirely for user input?
    • Recommendation: Use allowed_classes config only for internal APIs; avoid for public-facing endpoints.
  4. Does this resolve issues with Laravel’s JsonSerializable for private parent properties?
    • Test with models using protected/private fields in inheritance chains (e.g., User → BaseModel → Authenticatable).
  5. Will this integrate safely with Laravel’s caching layer?
    • Verify no side effects when serializing cached data (e.g., Redis::remember() with typed properties).
    • Critical: Test with serialized cache keys and event payloads.
  6. How does Opis/Closure v4 affect Laravel’s existing tooling?
    • Confirm no conflicts with illuminate/support, laravel/framework, or Laravel Forge/Envoyer.
    • Test: Run php artisan optimize and composer validate post-integration.
  7. What’s the impact on Laravel’s App\Exceptions\Handler?
    • Ensure no conflicts when both Handler and middleware use json_encode().
    • Mitigation: Use middleware only for API routes and avoid overriding Handler::render().
  8. Do we still support PHP 7.2/7.3 anywhere, and does that force us onto a version-sensitive path?
    • 3.2.4 silently broke PHP < 7.4. If any legacy Laravel app remains on 7.2/7.3, it must run 3.2.5+ and be covered by a dedicated CI job — otherwise the floor of our matrix is untested.
  9. Is PHP 8.5 on our roadmap, and does this release clear the last blocker?
    • Confirm the 3.2.5 deprecation fixes eliminate the last runtime warnings in serialization paths on 8.5, and that no other dependency (Opis, Laravel version) is the remaining gate.
  10. What is the upstream regression-testing posture?
  • The full-version CI matrix was added after a floor regression shipped. Confirm the matrix is now a required, blocking check so future patch releases cannot regress the minimum supported PHP.

Integration Approach

Stack Fit (Updated)

  • Primary Use Cases (Expanded)
    • Eloquent Model Serialization: Replace toArray()/toJson() for models with:
      • Parent class private properties (e.g., App\Models\Concerns\HasAuditLog).
      • Typed properties (e.g., protected ?string $metadata).
    • API Request Parsing: Use unserialize() with strict validation for:
      • GraphQL inputs.
      • Nested payloads (e.g., PATCH /users with complex updates).
    • Legacy Data Migration: Convert serialize()-based storage to JSON with:
      • Backward compatibility for pre-PHP 8.0 code (now verified down to PHP 7.2 on 3.2.5).
      • Typed property support.
    • Event-Driven Architectures: Serialize job payloads (Horizon/Redis queues) and broadcast events with typed properties and inheritance chains, where native json_encode() drops private parent state.
    • PHP 8.5 Upgrade Enablement (new): Treat the package as a prerequisite-cleared dependency in the Laravel 12+/PHP 8.5 upgrade plan rather than a migration risk item.

Migration Path (Updated)

  1. Constrain and pin: Set "zumba/json-serializer": "^3.2.5" — explicitly exclude 3.2.4 on any PHP < 7.4 host. Lock file review required.
  2. Baseline on 3.2.5: Re-run serialization correctness and performance baselines; do not carry forward 3.2.4 numbers (reflection call paths changed).
  3. Introduce at the boundary: Apply first to one API resource or one queue job class, not to global model toArray().
  4. Legacy-first: For pre-PHP 8.0 apps, migrate read paths (deserialization) before write paths to keep rollback cheap.
  5. Widen: Expand to additional endpoints/jobs only after the security audit of unserialize() inputs completes.

Compatibility (Updated)

  • PHP: 7.2 – 8.5, CI-verified per release. Our estate should declare an explicit floor; anything below 8.1 is a legacy-only exception requiring a dedicated test job.
  • Laravel: Compatible with Laravel 8/9/10/11 serialization and queue surfaces; Laravel 12+/PHP 8.5 now unblocked by 3.2.5.
  • Tooling: Opis/Closure v4 confirmed; re-validate Pint, PHPStan, Psalm on PHP 8.5 in CI.
  • Known incompatibility: 3.2.4 on PHP < 7.4 (fatal). Not a code-level incompatibility with our stack, but a version-pinning hazard.

Sequencing (Updated)

  1. Week 0: Pin ^3.2.5; enable automated dependency PRs with staging soak.
  2. Week 1: Add CI jobs at the floor (7.2/7.3, if applicable) and ceiling (8.5) of the matrix.
  3. Week 2–3: Pilot on one API resource + one Horizon job; capture performance and correctness deltas.
  4. Week 3–4: Security review of all unserialize() call sites; enforce whitelisting.
  5. Week 4+: Broaden adoption; fold 3.2.5 into the PHP 8.5 upgrade epic as a cleared dependency.

Operational Impact

Maintenance

  • Low burden, but non-zero attention required. MIT-licensed, actively patched (3.2.5 landed within one cycle of 3.2.4, closing issues #76/#77/#82 via a community PR). Upstream is responsive enough that forking is a contingency, not a plan.
  • New maintenance obligation: dependency upgrade reviews now require matrix-aware validation — a patch release can be green on 8.x and fatal on 7.x. Budget ~1–2 engineer-hours per patch release for soak + verification.
  • Deprecation hygiene: PHP 8.5 fixes mean we inherit less deprecation noise in our own logs, reducing false positives in error monitoring during the 8.5 upgrade.

Support

  • Internal support surface is narrow: manual service provider binding, no facade, no official Laravel package wrapper. Document the binding in the platform runbook to avoid tribal knowledge.
  • Escalation path: upstream GitHub issues (responsive), with fork as fallback. No commercial SLA — acceptable for a serialization utility, not acceptable if it becomes load-bearing for public-facing API parsing without an internal owner.
  • Security ownership: unserialize() call sites must have a named owner and a documented allowlist. 3.2.5 does not change this; the risk is unchanged from 3.2.4.

Scaling

  • Serialization is CPU/memory-bound and in the hot path. Scaling characteristics are per-request, not per-node-cluster: large object graphs (10K+ models in batch jobs) will show up as queue worker memory growth and API latency before they show up as infrastructure saturation.
  • Benchmark gate before wide rollout, and re-baseline post-3.2.5. Set an explicit ceiling (e.g., max object graph size) above which native toArray() is preferred.
  • Cache/queue amplification: serialized payloads in Redis and job payloads inflate storage and network egress. Monitor payload size distribution after rollout.

Failure Modes

Failure Mode Trigger Impact Detection / Mitigation
Fatal on legacy PHP Running 3.2.4 on PHP 7.2/7.3 Hard 500s / worker crashes on serialization Pin ^3.2.5; floor CI job; composer.lock audit
PHP 8.5 deprecation noise Pre-3.2.5 on 8.5 (SplObjectStorage, setAccessible()) Log flood, future hard failures Upgrade to 3.2.5; fail CI on deprecations
Unsafe deserialization Untrusted input reaching unserialize() Object injection / RCE-class exposure strict mode, allowed_classes allowlist, endpoint restriction
Silent state loss Private parent properties dropped by native path Missing fields in API responses / jobs Golden-file serialization tests on inheritance chains
Accessor bypass Serializer reads raw property, skipping getAttribute() Business logic (mutators, encryption casts) skipped Test with overridden accessors; review casts on serialized models
Exception handler collision Middleware and App\Exceptions\Handler both encoding JSON Malformed error responses Restrict middleware to API routes; don't override Handler::render()
Payload bloat Large graphs serialized into Redis/queues Memory pressure, latency Size ceilings, sampling, monitoring

Ramp-up

  • Low for a Laravel-fluent engineer: half a day to bind the provider, wire one resource, and write golden-file tests. The 3.2.5 fixes remove the two sharpest edges (typed properties, parent privates).
  • Higher for the security dimension: allowlisting and audit of unserialize() inputs is 1–2 days of focused review and should not be delegated to the same half-day integration window.
  • Matrix literacy required: whoever owns the dependency must understand the 7.2→8.5 support floor, since the last regression was floor-specific. Add this to the platform onboarding notes.
  • Net TPM position: Approve for adoption on ^3.2.5. 3.2.5 is a net-positive, non-breaking maintenance release that widens verified runtime coverage (7.2–8.5), clears the PHP 8.5 upgrade blocker, and repairs a regression that 3.2.4 introduced. It does not change the security risk profile, which remains the single item requiring active governance.
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.
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin