MediaWiki master
JsonDeserializableCodec.php
Go to the documentation of this file.
1<?php
8namespace MediaWiki\Json;
9
10use Wikimedia\JsonCodec\JsonClassCodec;
11
22class JsonDeserializableCodec implements JsonClassCodec {
23 private JsonDeserializer $codec;
24
25 public function __construct( JsonDeserializer $codec ) {
26 $this->codec = $codec;
27 }
28
30 public function toJsonArray( $obj ): array {
31 $result = $obj->jsonSerialize();
32 // Undo the work of JsonDeserializableTrait to avoid
33 // redundant storage of TYPE_ANNOTATION
34 unset( $result[JsonConstants::TYPE_ANNOTATION] );
35 return $result;
36 }
37
39 public function newFromJsonArray( string $className, array $json ) {
40 return $className::newFromJsonArray( $this->codec, $json );
41 }
42
44 public function jsonClassHintFor( string $className, string $keyName ) {
45 return null;
46 }
47}
A JsonClassCodec for objects implementing the JsonDeserializable interface.
jsonClassHintFor(string $className, string $keyName)
newFromJsonArray(string $className, array $json)
const TYPE_ANNOTATION
Name of the property where the class information is stored.