amazon-ion / ion-go

A Go implementation of Amazon Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
174 stars 31 forks source link

implement Marshaler and Unmarshaler in ion.Decimal #167

Closed whrami closed 3 years ago

whrami commented 4 years ago

Issue #, if available: N/A

Description of changes: ion.Decimal being a complex type with private struct fields, it is unable to be marshaled to/from JSON as fields in more complex structs.

This PR implements Marshaler for the ion.Decimal receiver type, and Unmarshaler for the *ion.Decimal receiver type.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

codecov-io commented 4 years ago

Codecov Report

Merging #167 into master will increase coverage by 0.06%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #167      +/-   ##
==========================================
+ Coverage   74.94%   75.00%   +0.06%     
==========================================
  Files          25       25              
  Lines        4865     4873       +8     
==========================================
+ Hits         3646     3655       +9     
+ Misses        724      723       -1     
  Partials      495      495              
Impacted Files Coverage Δ
ion/decimal.go 77.30% <100.00%> (+1.81%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 5d159f2...3feebbd. Read the comment docs.

zslayton commented 4 years ago

Hi, thanks for the PR!

The various Ion libraries follow this algorithm when down-converting Ion data to JSON, which is an inherently lossy transformation. In the case of decimal:

Decimals are printed as JSON number with precision preserved

A JSON Object is a perfectly valid representation, but that functionality would need to live in another library as it would not be consistent with our other language bindings.