JsonSerializer
extends BaseSerializer
in package
Transform data models to JSON.
Tags
Table of Contents
Constants
- JsonEncodeFlagsAllowedOptions = 0 | \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
- List of allowed options for {@see jsonEncodeFlags}.
- JsonEncodeFlagsDefaultOptions = 0 | \JSON_UNESCAPED_SLASHES
- List of mandatory options for $jsonEncodeFlags.
- JsonEncodeFlagsDefaults = 0 | \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION
- Defaults of {@see $jsonEncodeFlags}.
Properties
- $jsonEncodeFlags : int
- Flags for {@see \json_encode()}.
- $normalizerFactory : NormalizerFactory
Methods
- __construct() : mixed
- serialize() : string
- Serialize a {@see Bom} to string.
- realNormalize() : TNormalizedBom
- Normalize a {@see Bom} to the data structure that {@see realSerialize()} can handle.
- realSerialize() : string
- Serialize a {@see realNormalize() normalized} version of a {@see Bom}.
- getAllBomRefs() : array<string|int, BomRef>
- Get a list of all {@see BomRef} in {@see Bom}.
- normalize() : TNormalizedBom
- Normalize for serialization.
Constants
JsonEncodeFlagsAllowedOptions
List of allowed options for {@see jsonEncodeFlags}.
private
int
JsonEncodeFlagsAllowedOptions
= 0 | \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE
Bitmask consisting of JSON_*.
Some JSON flags could break the output, so they are not whitelisted.
Tags
JsonEncodeFlagsDefaultOptions
List of mandatory options for $jsonEncodeFlags.
private
int
JsonEncodeFlagsDefaultOptions
= 0 | \JSON_UNESCAPED_SLASHES
Bitmask consisting of JSON_*.
Tags
JsonEncodeFlagsDefaults
Defaults of {@see $jsonEncodeFlags}.
private
int
JsonEncodeFlagsDefaults
= 0 | \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION
Bitmask consisting of JSON_*.
These defaults are required to have valid output in the end.
Tags
Properties
$jsonEncodeFlags read-only
Flags for {@see \json_encode()}.
protected
int
$jsonEncodeFlags
Bitmask consisting of JSON_*.
Tags
$normalizerFactory read-only
protected
NormalizerFactory
$normalizerFactory
Methods
__construct()
public
__construct(NormalizerFactory $normalizerFactory[, int $jsonEncodeFlags = self::JsonEncodeFlagsDefaultOptions ]) : mixed
Parameters
- $normalizerFactory : NormalizerFactory
- $jsonEncodeFlags : int = self::JsonEncodeFlagsDefaultOptions
-
Bitmask consisting of JSON_*. see JsonEncodeFlagsAllowedOptions
serialize()
Serialize a {@see Bom} to string.
public
final serialize(Bom $bom[, bool|null $prettyPrint = null ]) : string
Parameters
- $bom : Bom
-
the BOM to serialize
- $prettyPrint : bool|null = null
-
whether to beatify the resulting string. A
null
value means no preference.
Return values
stringrealNormalize()
Normalize a {@see Bom} to the data structure that {@see realSerialize()} can handle.
protected
realNormalize(Bom $bom) : TNormalizedBom
Parameters
- $bom : Bom
Return values
TNormalizedBom —a version of the Bom that was normalized for serialization
realSerialize()
Serialize a {@see realNormalize() normalized} version of a {@see Bom}.
protected
realSerialize(mixed $normalizedBom, bool|null $prettyPrint) : string
Parameters
- $normalizedBom : mixed
-
a version of the Bom that was normalized for serialization
- $prettyPrint : bool|null
Return values
stringgetAllBomRefs()
Get a list of all {@see BomRef} in {@see Bom}.
private
getAllBomRefs(Bom $bom) : array<string|int, BomRef>
The list might contain duplicates.
Parameters
- $bom : Bom
Tags
Return values
array<string|int, BomRef>normalize()
Normalize for serialization.
private
normalize(Bom $bom) : TNormalizedBom
Also utilizes BomRefDiscriminator to guarantee that each BomRef has a unique value.
Parameters
- $bom : Bom
Tags
Return values
TNormalizedBom —a version of the Bom that was normalized for serialization