cnabio / cnab-go

A Go implementation of CNAB Core 1.0
MIT License
69 stars 37 forks source link

Cannot write bundles that use decimal numbers #115

Closed carolynvs closed 5 years ago

carolynvs commented 5 years ago

Since bundles are written using canonical json, and canonical json does not allow for decimal numbers only integers, our current use of float64 to store properties such as Maximum, Minimum, etc is a problem. Any bundles with any of those fields set is unwritable with an error like json: unsupported value: 0.5.

Other fields like Default allow you to store a decimal number and should also gracefully be handled as part of any fix for the other fields.

One fix would be to switch from float64 to json.Number. Then in WriteTo we could check if fields like Default which store an interface{} if they contain a non-integer float and stringify it.

carolynvs commented 5 years ago

In the cnab meeting today we discussed various solutions and decided against converting non-integer numbers to string. The reason being that the schema requires that the value for these fields be represented with a number, and marshaling to a string would require an even more customized version of the json schema draft 7 to allow for the strings.

Right now we are going to switch the schema from number to integer. On the cnab-go side the change we agreed upon is to change from float to integer to store values such as Maximum.

It is up to each calling tool to ensure that Default does not contain a non-integer float.

carolynvs commented 5 years ago

I'll submit a PR shortly with the proposed change.