Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 1 KB

serializer.md

File metadata and controls

47 lines (32 loc) · 1 KB

Serializer

JsonApiClient provides Serializer to convert a parsed JSON API document into other formats. Till now JsonApiClient comes only with an ArraySerializer.

ArraySerializer

You can get all data as an array using the ArraySerializer.

Get the containing data as array

use Art4\JsonApiClient\Serializer\ArraySerializer;

$serializer = new ArraySerializer();
$array = $serializer->serialize($document);

var_dump($array);

This returns:

array(1) {
  ["meta"] => object(Art4\JsonApiClient\V1\Meta)#9 (2) { ... }
}

If you want a full array without any objects, set the recursive configuration into the ArraySerializer to parse all objects recursively into arrays.

use Art4\JsonApiClient\Serializer\ArraySerializer;

$serializer = new ArraySerializer(['recursive' => true]);
$array = $serializer->serialize($document);

var_dump($array);

This returns:

array(1) {
  ["meta"] => array(1) {
    ["info"] => string(28) "Testing the JsonApiClient library."
  }
}