Skip to content

integer number in json but dump into cbor the number is float #67

Description

@atenjin

testcase in the code:

func TestResolvedValIsJsonable(t *testing.T) {

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions