ProductJsonSerializer

Extends \AbstractJsonSerializer

Class ProductJsonSerializer

This class will serialize and deserialize a Product entity. It can be used into many places where PHP interacts with external requests such as AJAX or API communication.

category

System

package

Extensions

subpackage

Serializers

Methods

AbstractJsonSerializer Constructor

__construct() 
inherited

If you override this constructor do not forget to call it from the child class.

Deserialize Addon Values

_deserializeAddonValues( $json) : array
inherited

Common method for deserializing addon values in various resource serializer classes.

Arguments

$json

Response

array

Deserialize Images

_deserializeImages( $json) : \ProductImageContainer
Throws
\InvalidArgumentException

Through "addAdditional"

\RuntimeException

Through "_deserializeLanguageSpecificProperty"

Arguments

$json

Response

\ProductImageContainer

Deserialize Language Specific Property

_deserializeLanguageSpecificProperty(mixed $object, \stdobject $json, string $property,  $type = 'StringType') 
inherited

This method will deserialize the value of a JSON property and set the value to the object by using the corresponding setter method.

Throws
\RuntimeException

If the setter method does not exist.

Arguments

$object

mixed

The object being deserialized.

$json

\stdobject

The JSON object containing the property value.

$property

string

The property name to be deserialized.

$type

Deserialize Settings

_deserializeSettings(\ProductSettingsInterface $settings,  $json) : \ProductSettingsInterface

Arguments

$json

Response

\ProductSettingsInterface

Serialize Addon Values

_serializeAddonValues(\KeyValueCollection $addonValues) : array
inherited

Common method for serializing addon values in various resource serializer classes.

Arguments

$addonValues

\KeyValueCollection

Response

array

Serialize Images

_serializeImages(\ProductImageContainerInterface $imageContainer) : array

Arguments

Response

array

Serialize Language Specific Property

_serializeLanguageSpecificProperty(mixed $object, string $property) : array
inherited

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.

Throws
\RuntimeException

If there is no getter for the provided property.

Arguments

$object

mixed

The object instance containing the property.

$property

string

The property name to be serialized.

Response

array

Serialize Settings

_serializeSettings(\ProductSettingsInterface $settings) : array

Arguments

Response

array

Decodes a JSON string and performs some basic validation.

decodeJson(mixed $string) : array

Arguments

$string

mixed

The (potential) JSON string

Response

array

The decoded JSON array

deserialize

deserialize( $string,  $baseObject = null) 
inherited abstract

Arguments

$string

$baseObject

JSON Encode Wrapper

jsonEncode(array $data) : string
inherited

This function provides PHP v5.3 compatibility and it should be used when serialized objects need to be encoded directly from the serializer instance.

Arguments

$data

array

Contains the data to be JSON encoded.

Response

string

Returns the encoded JSON string that represents the data.

serialize

serialize( $object,  $encode = true) 
inherited abstract

Arguments

$object

$encode

Serializes an array of ProductInterfaces to a JSON string.

serializeProductArray(array $storedProducts, boolean $encode = true) : array|string

Arguments

$storedProducts

array

The array of ProductInterfaces

$encode

boolean

Indicates if the result should be returned JSON encoded.

Response

array|string

Either a JSON string or the serialized array (depends on the $encode parameter)

Properties

Used for the resources that require multiple languages.

languageProvider : \LanguageProviderInterface
inherited