ornament / json
JSON model for the Ornament ORM framework
Requires
- php: >=8.1
- ornament/core: ^0.16.0
Requires (Dev)
- gentry/gentry: ^0.16.0
- toast/unit: ^2.0
This package is auto-updated.
Last update: 2024-12-12 20:59:06 UTC
README
JSON helpers for Ornament ORM
Installation
$ composer require ornament/json
Usage
This package consists of two traits one can use
for easy JSON seriliazing, as
well as a property decorator for JSON properties.
The serializers
Models should implement the JsonSerializable
interface. Then, simply use
either SerializeAll
(to enable serialization of both public and protected
properties) or SerializeOnlyPublic
(for only public properties).
The decorator
Annotate your property with @var Ornament\Json\Json
. If the value is input as
a string, the decorator tries to json_decode()
it. If the value is not a
string to begin with, it is left alone.
The decorator throws a DomainException
if the string passed is not valid JSON.