Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
JsonConverter.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 
16 {
22  const CONTENT_TYPE_HEADER = 'Content-Type: application/json';
23 
27  const CONTENT_MEDIA_TYPE = 'application/json';
28 
32  private $serializer;
33 
37  public function __construct(Json $serializer)
38  {
39  $this->serializer = $serializer;
40  }
41 
47  public function fromBody($body)
48  {
49  $decodedBody = $this->serializer->unserialize($body);
50  return $decodedBody === null ? [$body] : $decodedBody;
51  }
52 
58  public function toBody(array $data)
59  {
60  return $this->serializer->serialize($data);
61  }
62 
66  public function getContentTypeHeader()
67  {
68  return sprintf('Content-Type: %s', self::CONTENT_MEDIA_TYPE);
69  }
70 
74  public function getContentMediaType(): string
75  {
77  }
78 }