wiki.techinc.nl/tests/phpunit/mocks/json
C. Scott Ananian 96e4f5d840 JsonCodec: fix en/decoding of nested objects and stdClass objects
Add a type annotation when encoding `stdClass` objects so that we can
be sure to decode them as objects instead of arrays.

This avoids issues such as that seen in the Graph extension (T312589)
where an extension data key is stored as a stdClass.  If ParserOutput
was computed fresh, a subsequent getExtensionData(..) call will return
a stdClass object, but if the ParserOutput was cached, getExtensionData()
would return an array.  After this change the return type is always
consistent.

Properly handle nested objects: encode all object values returned by
JsonSerializable::jsonSerialize() (so that client is not responsible
for implementing this correctly), and decode all object values *before*
calling JsonUnserializable::newFromJsonArray (again, so that the
client is not responsible for decoding its property values).  The new
behavior matches how serialize/unserialize is handled in the 'naive'
JsonUnserializable{Sub,Super}Class test cases; ParserOutput (the only
users of JsonCodec in core) was doing an extra manual decode for
the ExtensionData array in ParserOutput::initFromJson that is no longer
necessary.

The GrowthExperiments and SemanticMediaWiki extensions were working
around the non-recursive nature of JsonCodec; this patch depends on
patches to GrowthExperiments to make it agnostic about whether object
unserialization occurs before or after ::newFromJsonArray() is called,
which can then be further cleaned up once this is released.
A pull request for SemanticMediaWiki has also been submitted.

Bug: T312589
Depends-On: I3413609251f056893d3921df23698aeed40754ed
Change-Id: Id7d0695af40b9801b42a9b82f41e46118da288dc
2023-01-12 14:12:32 -05:00
..
JsonUnserializableSubClass.php
JsonUnserializableSuperClass.php