-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BREAKING] 0 is converted to BigInteger rather than Int32 in v0.49 #164
Comments
Hi @ibiernacki, So, We switched to I won't be able to fix this today, as I need to switch to another urgent project (wish this was opened 30 minutes earlier). AS a quick workaround you can use: PS /> 0 | ConvertFrom-Yaml | ConvertTo-Yaml -JsonCompatible
0 I will try to push a new release in the next couple of days. |
Here is a more complex example: PS /home/gabriel> Import-Module powershell-yaml
PS /home/gabriel> $aReallyBigNumber = [System.Numerics.BigInteger]::Parse("9999999999999999999999999999999999999999999999999")
PS /home/gabriel> $toSerialize = @{"aString" = "test"; "aBigNumber" = $aReallyBigNumber}
PS /home/gabriel> ConvertTo-Json $toSerialize
{
"aString": "test",
"aBigNumber": {
"IsPowerOfTwo": false,
"IsZero": false,
"IsOne": false,
"IsEven": false,
"Sign": 1
}
}
PS /home/gabriel> ConvertTo-Yaml -JsonCompatible $toSerialize
{"aString": "test", "aBigNumber": 9999999999999999999999999999999999999999999999999} |
Yup. The switch to BigInt was done to prevent the implicit conversion that powershell does to scientific notation, as that looses precision. Gah. Pushing a fix soon. Please run any test suits in your apps and let me know if anything else breaks in the current version, so I can address any lingering issues and push a new release. |
A fix for the case where Note that really large numbers will still be cast as |
Leaving open until a release is published. If you spot any other issues after running your tests, feel free to open a bug. Releasing a new version in 2 days to allow any other issues to be reported and fixed all in one release. |
Ouch: PS /home/gabriel> ('9223372036854775808' | ConvertFrom-Json).GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True BigInteger System.ValueType
PS /home/gabriel> '9223372036854775808' | ConvertFrom-Json | ConvertTo-Json
{
"IsPowerOfTwo": true,
"IsZero": false,
"IsOne": false,
"IsEven": true,
"Sign": 1
} Apparently this was reported here: PowerShell/PowerShell#20989 and fixed here: PowerShell/PowerShell#21000 |
I released a new version with a fix for this, as I really need to move to another project for a while. If anything major comes up after you folks get a chance to test. I'll try to address it. |
In the latest version
0.4.9
, zero ("0") are converted to BigInteger, while other integers use Int32:Converting "0":
Converting other numbers:
Why it matters?
In our scenario, we are merging several objects and eventually serialize it as a json. There is no consistency while serializing fields, for example:
The text was updated successfully, but these errors were encountered: