JSON Schema Deserialization in Laravel 13.14
Laravel #Laravel #PHP #JSON Schema #Deserialization #Queue #HTTP Client

JSON Schema Deserialization in Laravel 13.14

3 min read Mohamed Said Mohamed Said

Laravel 13.14.0 has been released, bringing a significant enhancement to the JSON Schema library with the introduction of a deserializer. This new feature allows developers to reconstruct Type objects from raw JSON Schema arrays, complementing the existing serializer functionality.

Previously, the JSON Schema library in Laravel primarily supported serialization, enabling the conversion of Type objects into array representations. The addition of JsonSchema::fromArray() by @pushpak1300 now enables the reverse process. This is particularly useful when receiving a JSON Schema definition over the network or from a configuration file and needing to work with it as structured Type objects within the application. The new Deserializer mirrors the Serializer, ensuring a seamless round-trip for schema definitions.

use Illuminate\Support\Facades\JsonSchema;

$type = JsonSchema::fromArray([
    'type' => 'object',
    'properties' => [
        'name' => ['type' => 'string', 'minLength' => 1],
        'age' => ['type' => 'integer', 'minimum' => 0],
    ],
    'required' => ['name'],
]);

// $type will be an instance of ObjectType

This functionality ensures that a schema serialized and then deserialized using these methods will result in an equivalent Type object.

Queue Job Attribute Inheritance Fix

@mattiasgeniar addressed an edge case within the queue system concerning attribute inheritance. Previously, child queue classes could not override queue attributes, such as #[Timeout(40)], defined in their parent classes. The fix establishes a clear hierarchy: attributes defined within the same class take precedence over default properties, runtime modifications remain prioritized, and crucially, properties defined in child classes now successfully override inherited queue attributes from parent classes.

Visibility into Pending Jobs

To improve the debugging and monitoring of background tasks, @jackbayliss has added a queue property to the InspectedJob class. This enhancement allows developers to easily identify the specific queue to which a pending job is assigned, supporting both the database and Redis queue drivers.

HTTP Client Caching Improvements

A bug affecting the HTTP client's caching mechanism has been resolved by @Button99. Previously, valid falsy JSON payloads such as false, 0, or null were not being cached correctly. The fix introduces a dedicated boolean flag to track the decoding status, preventing falsy decoded values from being misinterpreted as un-decoded and thus re-decoded on subsequent accesses.

Other Notable Fixes

This release also includes several other important fixes:

  • Message::embed data attachment handling has been improved by @miladev95.
  • The treatment of null headers has been corrected by @GrahamCampbell.
  • Compatibility of Request::createFromBase() with Symfony 8.1 has been ensured by @irabbi360.
  • The lazy refresh hook is now registered on all connections by @tontonsb.
  • The cloud logging formatter has been namespaced by @timacdonald.
  • Documentation for DebounceFor has been updated by @jackbayliss to clarify that it is measured in seconds.

Key Takeaways:

  • New JsonSchema::fromArray() enables deserialization of JSON Schema arrays into Type objects.
  • Child queue properties now correctly override inherited attributes from parent classes.
  • The InspectedJob class now includes a queue property for better job inspection.
  • HTTP client caching now correctly handles falsy JSON payloads.

For more details, refer to the official changelog and the full v13.14.0 release notes.

Source: https://laravel-news.com/laravel-13-14-0

Found this useful?

Frequently Asked Questions

3 questions
Q01 What is the new `JsonSchema::fromArray()` method in Laravel 13.14.0?
The `JsonSchema::fromArray()` method allows developers to convert a raw JSON Schema array definition back into a `Type` object, enabling bidirectional manipulation of JSON Schemas within Laravel.
Q02 How does Laravel 13.14.0 improve queue job attribute inheritance?
Child queue classes can now override queue attributes, such as timeouts, that were previously defined in parent classes. This provides more granular control over job configurations.
Q03 What bug was fixed regarding HTTP client caching in Laravel 13.14.0?
A bug where falsy JSON payloads (like `false`, `0`, or `null`) were not cached correctly has been fixed. The HTTP client now properly caches these values by using a separate flag to track decoding status.

Continue reading

More Articles

View all