ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.86k stars 295 forks source link

Regression: Unmarshal empty JSON array as new empty Go array #181

Closed sttts closed 8 years ago

sttts commented 8 years ago

This was fixed before: https://github.com/ugorji/go/issues/119. But with the master branch this gives a nil slice again:

var a []int
codec.NewDecoderBytes([]byte(`[]`), jsonHandle).Decode(&a)
ugorji commented 8 years ago

I just ran the code below, and got the response below:

package main

import ( "fmt"

"github.com/ugorji/go/codec"

)

func main() { var a []int var s = []byte([]) var h codec.JsonHandle codec.NewDecoderBytes(s, &h).Decode(&a) fmt.Printf("a is now: %v of type: %T and is nil: %v\n", a, a, a == nil) }

Output: a is now: [] of type: []int and is nil: false

I'm not sure what you expect to happen, but this works.

Next time filing an issue, please include a reproducer that can be run with "go run main.go" or "go test". Also, include what you expect on the standard output, and what you get. This makes it easier to explicitly understand what you think the bug is.

sttts commented 8 years ago

Thanks for verifying. You are right: the issue is fixed in master. My minimal test example was wrong, passing a non-reference struct to Decode, giving me the impression it's also broken on master.

The version we have in Kubernetes is from October 2015, before your fix. An update to master should fix it.