ornament/json

JSON model for the Ornament ORM framework

0.15.0 2022-11-02 15:00 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.