go: bug: MapValueReset has no effect

The sample code below doesn’t seem to work as it should:

package main

import (
	"bytes"
	"fmt"

	"github.com/ugorji/go/codec"
)

func main() {

	h := &codec.JsonHandle{}
	h.MapValueReset = true

	d := bytes.NewBuffer([]byte(`{"map": {"a": 1}}`))
	dec := codec.NewDecoder(d, h)

	o := struct {
		Map map[string]interface{} `json:"map"`
	}{}

	o.Map = map[string]interface{}{"b": 1}

	if err := dec.Decode(&o); err != nil {
		panic(err)
	}

	fmt.Println(o.Map)
}

This prints:

map[a:1 b:1]

Since I set MapValueReset = true, I would expect it to print:

map[a:1]

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

ok that’s what I though. We have some idiotic test suite that prevent us to use omitempty. A good reason to remind them to fix that crap.

I know you have made a ton of improvement which is why I really don’t want to get stuck with 1.1.4 😃

Thanks for all the explanations!

Question: why do you have json and msgpack in your struct tags?

We tried many encoders, and we just kept them for backward compat (we use msgpackHandle.TypeInfos = codec.NewTypeInfos([]string{"msgpack"}))