JsonEncoder
in package
implements
EncoderInterface, DecoderInterface
Encodes JSON data.
Tags
Table of Contents
Interfaces
Constants
- FORMAT = 'json'
Properties
- $decodingImpl : mixed
- $encodingImpl : mixed
- $defaultContext : mixed
Methods
- __construct() : mixed
- decode() : mixed
- Decodes a string into PHP data.
- encode() : string
- Encodes data into the given format.
- supportsDecoding() : bool
- Checks whether the deserializer can decode from given format.
- supportsEncoding() : bool
- Checks whether the serializer can encode to given format.
Constants
FORMAT
public
mixed
FORMAT
= 'json'
Properties
$decodingImpl
protected
mixed
$decodingImpl
$encodingImpl
protected
mixed
$encodingImpl
$defaultContext
private
mixed
$defaultContext
= [\Symfony\Component\Serializer\Encoder\JsonDecode::ASSOCIATIVE => true]
Methods
__construct()
public
__construct([JsonEncode $encodingImpl = null ][, JsonDecode $decodingImpl = null ][, array<string|int, mixed> $defaultContext = [] ]) : mixed
Parameters
- $encodingImpl : JsonEncode = null
- $decodingImpl : JsonDecode = null
- $defaultContext : array<string|int, mixed> = []
decode()
Decodes a string into PHP data.
public
decode(string $data, string $format[, array<string|int, mixed> $context = [] ]) : mixed
Parameters
- $data : string
-
Data to decode
- $format : string
-
Format name
- $context : array<string|int, mixed> = []
-
Options that decoders have access to
The format parameter specifies which format the data is in; valid values depend on the specific implementation. Authors implementing this interface are encouraged to document which formats they support in a non-inherited phpdoc comment.
encode()
Encodes data into the given format.
public
encode(mixed $data, string $format[, array<string|int, mixed> $context = [] ]) : string
Parameters
- $data : mixed
-
Data to encode
- $format : string
-
Format name
- $context : array<string|int, mixed> = []
-
Options that normalizers/encoders have access to
Return values
stringsupportsDecoding()
Checks whether the deserializer can decode from given format.
public
supportsDecoding(string $format) : bool
Parameters
- $format : string
-
Format name
Return values
boolsupportsEncoding()
Checks whether the serializer can encode to given format.
public
supportsEncoding(string $format) : bool
Parameters
- $format : string
-
Format name