Error deserializing whole-number float values
Physikbuddha opened this issue · comments
Physikbuddha commented
Imagine the following class:
class Foo {
public float $floatNumber;
}
This works just fine:
$foo = new Foo();
$foo->floatNumber = 1234.5;
$json = $this->serde->serialize($foo, 'json'); // Value reads {"floatNumber":1234.5}
$bar = $this->serde->deserialize($json, 'json', Foo::class);
However, using a (valid) whole-number float causes the Deserializer to throw an exception:
$foo = new Foo();
$foo->floatNumber = 1234.0;
$json = $this->serde->serialize($foo, 'json'); // Value reads {"floatNumber":1234}
$bar = $this->serde->deserialize($json, 'json', Foo::class);
Crell\Serde\TypeMismatch
Expected value of type float when writing to property floatNumber, but found type int.
vendor\crell\serde\src\TypeMismatch.php line 16
Larry Garfield commented
Hm, yep, that should be allowed. I'm still not 100% certain if the type checking is done right in the system, but I've fixed it for now in 71f84c3.
Physikbuddha commented
I can confirm that it now works.