4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
23 namespace MediaWiki\Json
;
25 use InvalidArgumentException
;
28 * Deserializes things from JSON.
31 * @package MediaWiki\Json
33 interface JsonDeserializer
{
36 * Restore an instance of simple type or JsonDeserializable subclass
37 * from the JSON serialization. It supports passing array/object to
38 * allow manual decoding of the JSON string if needed.
40 * @note JSON objects are unconditionally deserialized as PHP associative
41 * arrays, and not as instances of \stdClass.
43 * @phpcs:ignore MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam
44 * @param array|string|object $json
45 * @param string|null $expectedClass What class to expect in deserialization.
46 * If null, no expectation. Must be a descendant of JsonDeserializable.
47 * @throws InvalidArgumentException if the passed $json can't be deserialized.
50 public function deserialize( $json, ?
string $expectedClass = null );
53 * Backwards-compatibility alias for deserialize()
55 * @deprecated since 1.43
57 public function unserialize( $json, ?
string $expectedClass = null );
60 * Helper to deserialize an array of JsonDeserializable instances or simple types.
64 public function deserializeArray( array $array ): array;
67 * Backwards-compatibility alias for deserializeArray()
69 * @deprecated since 1.43
71 public function unserializeArray( array $array ): array;
74 /** @deprecated class alias since 1.43 */
75 class_alias( JsonDeserializer
::class, 'MediaWiki\\Json\\JsonUnserializer' );