diff --git a/Civi/RemoteTools/Util/JsonConverter.php b/Civi/RemoteTools/Util/JsonConverter.php index 40dea03..ada2f4c 100644 --- a/Civi/RemoteTools/Util/JsonConverter.php +++ b/Civi/RemoteTools/Util/JsonConverter.php @@ -29,7 +29,7 @@ final class JsonConverter { * @throws \JsonException */ public static function toArray(\stdClass $data): array { - $result = \json_decode(\json_encode($data, JSON_THROW_ON_ERROR), TRUE); + $result = \json_decode(\json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION), TRUE); Assert::isArray($result); return $result; @@ -45,7 +45,7 @@ public static function toStdClass(array $data): \stdClass { return new \stdClass(); } - $result = \json_decode(\json_encode($data, JSON_THROW_ON_ERROR)); + $result = \json_decode(\json_encode($data, JSON_THROW_ON_ERROR | JSON_PRESERVE_ZERO_FRACTION)); Assert::isInstanceOf($result, \stdClass::class); return $result; diff --git a/tests/phpunit/Civi/RemoteTools/Util/JsonConverterTest.php b/tests/phpunit/Civi/RemoteTools/Util/JsonConverterTest.php index 0d8f2b3..9a88aec 100644 --- a/tests/phpunit/Civi/RemoteTools/Util/JsonConverterTest.php +++ b/tests/phpunit/Civi/RemoteTools/Util/JsonConverterTest.php @@ -13,15 +13,17 @@ final class JsonConverterTest extends TestCase { public function testToArray(): void { $object = new \stdClass(); $object->foo = 'bar'; + $object->bar = 2.0; - static::assertSame(['foo' => 'bar'], JsonConverter::toArray($object)); + static::assertSame(['foo' => 'bar', 'bar' => 2.0], JsonConverter::toArray($object)); } public function testToStdClass(): void { - $array = ['foo' => 'bar']; + $array = ['foo' => 'bar', 'bar' => 2.0]; $object = JsonConverter::toStdClass($array); static::assertSame('bar', $object->foo); + static::assertSame(2.0, $object->bar); } public function testToStdClassEmptyArray(): void {