AbstractJsonSerializer
in package
implements
SerializerInterface
Abstract Json Serializer
Serializers that extend this class should parse and encode entities so that they can be used in the shop's APIs.
Serialization must follow the "null" approach in order to enhance response clarity. That means that serializers must provide a null value than an empty string or an omitted node.
Tags
Interfaces, Classes and Traits
- SerializerInterface
- Interface SerializerInterface
Table of Contents
- $languageProvider : LanguageProviderInterface
- Used for the resources that require multiple languages.
- __construct() : mixed
- AbstractJsonSerializer Constructor
- deserialize() : mixed
- jsonEncode() : string
- JSON Encode Wrapper
- serialize() : mixed
- _deserializeAddonValues() : array<string|int, mixed>
- Deserialize Addon Values
- _deserializeLanguageSpecificProperty() : mixed
- Deserialize Language Specific Property
- _serializeAddonValues() : array<string|int, mixed>
- Serialize Addon Values
- _serializeLanguageSpecificProperty() : array<string|int, mixed>
- Serialize Language Specific Property
Properties
$languageProvider
Used for the resources that require multiple languages.
protected
LanguageProviderInterface
$languageProvider
Methods
__construct()
AbstractJsonSerializer Constructor
public
__construct() : mixed
If you override this constructor do not forget to call it from the child class.
Return values
mixed —deserialize()
public
abstract deserialize(mixed $string[, mixed $baseObject = null ]) : mixed
Parameters
- $string : mixed
- $baseObject : mixed = null
Return values
mixed —jsonEncode()
JSON Encode Wrapper
public
jsonEncode(array<string|int, mixed> $data) : string
This function provides PHP v5.3 compatibility and it should be used when serialized objects need to be encoded directly from the serializer instance.
Parameters
- $data : array<string|int, mixed>
-
Contains the data to be JSON encoded.
Return values
string —Returns the encoded JSON string that represents the data.
serialize()
public
abstract serialize(mixed $object[, mixed $encode = true ]) : mixed
Parameters
- $object : mixed
- $encode : mixed = true
Return values
mixed —_deserializeAddonValues()
Deserialize Addon Values
protected
_deserializeAddonValues( $json) : array<string|int, mixed>
Common method for deserializing addon values in various resource serializer classes.
Parameters
Return values
array<string|int, mixed> —_deserializeLanguageSpecificProperty()
Deserialize Language Specific Property
protected
_deserializeLanguageSpecificProperty(mixed $object, stdobject $json, string $property[, mixed $type = 'StringType' ]) : mixed
This method will deserialize the value of a JSON property and set the value to the object by using the corresponding setter method.
Parameters
- $object : mixed
-
The object being deserialized.
- $json : stdobject
-
The JSON object containing the property value.
- $property : string
-
The property name to be deserialized.
- $type : mixed = 'StringType'
Tags
Return values
mixed —_serializeAddonValues()
Serialize Addon Values
protected
_serializeAddonValues(KeyValueCollection $addonValues) : array<string|int, mixed>
Common method for serializing addon values in various resource serializer classes.
Parameters
- $addonValues : KeyValueCollection
Return values
array<string|int, mixed> —_serializeLanguageSpecificProperty()
Serialize Language Specific Property
protected
_serializeLanguageSpecificProperty(mixed $object, string $property) : array<string|int, mixed>
In order for this method to work there has to be a proper getter method in the object instance. Otherwise a RuntimeException will be thrown.
Parameters
- $object : mixed
-
The object instance containing the property.
- $property : string
-
The property name to be serialized.