integer number in json but dump into cbor the number is float
- Dominant language
- Go
- Stars
- 37
- Forks
- 26
- PR merge metrics
- No merged PRs in 30d
Description
testcase in the code:
https://github.com/ipfs/go-ipld-cbor/blob/e249008b68731703a093b723253be5175d518ed0/node_test.go#L337
```go
func TestResolvedValIsJsonable(t *testing.T) {
// we can see that the value in map "foo" for key "bar" and "baz" is **interger**
data := `{
"foo": {
"bar": 1,
"baz": 2
}
}`
n, err := FromJSON(strings.NewReader(data), mh.SHA2_256, -1)
if err != nil {
t.Fatal(err)
}
// ...
}
```
but in function `FromJSON`
```go
func FromJSON(r io.Reader, mhType uint64, mhLen int) (*Node, error) {
var m interface{}
// receive the preview str, it would result be like
// map { "bar" => 1 (float64) ; "baz" => 2 (float64) }
err := json.NewDecoder(r).Decode(&m)
if err != nil {
return nil, err
}
// and then, cbor would use float64 to serialize, but in fact, this value is an integer
obj, err := convertToCborIshObj(m)
if err != nil {
return nil, err
}
return WrapObject(obj, mhType, mhLen)
}
```
I think this is a wrong case. Please check it, thanks.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.