|
@@ -210,8 +210,14 @@ class NormalizerFormatter implements FormatterInterface
|
|
|
$accessor = new \ArrayObject($data);
|
|
$accessor = new \ArrayObject($data);
|
|
|
$value = (string) $accessor['__PHP_Incomplete_Class_Name'];
|
|
$value = (string) $accessor['__PHP_Incomplete_Class_Name'];
|
|
|
} elseif (method_exists($data, '__toString')) {
|
|
} elseif (method_exists($data, '__toString')) {
|
|
|
- /** @var string $value */
|
|
|
|
|
- $value = $data->__toString();
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ /** @var string $value */
|
|
|
|
|
+ $value = $data->__toString();
|
|
|
|
|
+ } catch (\Throwable) {
|
|
|
|
|
+ // if the toString method is failing, use the default behavior
|
|
|
|
|
+ /** @var null|scalar|array<mixed[]|scalar|null> $value */
|
|
|
|
|
+ $value = json_decode($this->toJson($data, true), true);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
// the rest is normalized by json encoding and decoding it
|
|
// the rest is normalized by json encoding and decoding it
|
|
|
/** @var null|scalar|array<mixed[]|scalar|null> $value */
|
|
/** @var null|scalar|array<mixed[]|scalar|null> $value */
|