JsonConverter
extends Converter
in package
Json converter with the ability to serialize/unserialize DTO objects using JSON.
Table of Contents
Constants
- JSON_FLAGS = \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION
Properties
- $marshaller : MarshallerInterface
Methods
- __construct() : mixed
- fromPayload() : mixed|void
- getEncodingType() : string
- Returns associated encoding type.
- toPayload() : Payload|null
- Implements conversion of a single value to Payload. Must return null if value can't be encoded.
- create() : Payload
- createDefaultMarshaller() : MarshallerInterface
- createDefaultReader() : ReaderInterface
- errorInvalidType() : DataConverterException
- errorInvalidTypeName() : DataConverterException
- toHashMap() : array<string|int, mixed>
- unmarshal() : T
Constants
JSON_FLAGS
public
int
JSON_FLAGS
= \JSON_THROW_ON_ERROR | \JSON_PRESERVE_ZERO_FRACTION
Properties
$marshaller
private
MarshallerInterface
$marshaller
Methods
__construct()
public
__construct([MarshallerInterface|null $marshaller = null ]) : mixed
Parameters
- $marshaller : MarshallerInterface|null = null
fromPayload()
public
fromPayload(Payload $payload, Type $type) : mixed|void
Parameters
- $payload : Payload
- $type : Type
Tags
Return values
mixed|voidgetEncodingType()
Returns associated encoding type.
public
getEncodingType() : string
Return values
stringtoPayload()
Implements conversion of a single value to Payload. Must return null if value can't be encoded.
public
toPayload(mixed $value) : Payload|null
Parameters
- $value : mixed
Tags
Return values
Payload|nullcreate()
protected
create(string $data) : Payload
Parameters
- $data : string
Return values
PayloadcreateDefaultMarshaller()
private
static createDefaultMarshaller() : MarshallerInterface
Return values
MarshallerInterfacecreateDefaultReader()
private
static createDefaultReader() : ReaderInterface
Return values
ReaderInterfaceerrorInvalidType()
private
errorInvalidType(Type $type, mixed $data) : DataConverterException
Parameters
- $type : Type
- $data : mixed
Return values
DataConverterExceptionerrorInvalidTypeName()
private
errorInvalidTypeName(Type $type) : DataConverterException
Parameters
- $type : Type
Return values
DataConverterExceptiontoHashMap()
private
toHashMap(object|array<string|int, mixed> $context) : array<string|int, mixed>
Parameters
- $context : object|array<string|int, mixed>
Return values
array<string|int, mixed>unmarshal()
private
unmarshal(object|array<string|int, mixed> $data, ReflectionClass<string|int, T> $reflection) : T
Parameters
- $data : object|array<string|int, mixed>
- $reflection : ReflectionClass<string|int, T>