MediaWiki master
JsonDeserializableCodec.php
Go to the documentation of this file.
1<?php
22namespace MediaWiki\Json;
23
24use Wikimedia\JsonCodec\JsonClassCodec;
25
34class JsonDeserializableCodec implements JsonClassCodec {
35 private JsonDeserializer $codec;
36
37 public function __construct( JsonDeserializer $codec ) {
38 $this->codec = $codec;
39 }
40
42 public function toJsonArray( $obj ): array {
43 $result = $obj->jsonSerialize();
44 // Undo the work of JsonDeserializableTrait to avoid
45 // redundant storage of TYPE_ANNOTATION
46 unset( $result[JsonConstants::TYPE_ANNOTATION] );
47 return $result;
48 }
49
51 public function newFromJsonArray( string $className, array $json ) {
52 return $className::newFromJsonArray( $this->codec, $json );
53 }
54
56 public function jsonClassHintFor( string $className, string $keyName ) {
57 return null;
58 }
59}
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.