Closed masterada closed 6 years ago
Json encoding the same struct twice with different tags does not work, first tag is used for second encode as well.
type t struct { Field string `foo:"field_foo" bar:"field_bar"` } v := &t{ Field: "value", } handle := &codec.JsonHandle{} handle.TypeInfos = codec.NewTypeInfos([]string{"foo"}) var b []byte enc := codec.NewEncoderBytes(&b, handle) enc.Encode(v) log.Print(string(b)) handle = &codec.JsonHandle{} handle.TypeInfos = codec.NewTypeInfos([]string{"bar"}) b = nil enc = codec.NewEncoderBytes(&b, handle) enc.Encode(v) log.Print(string(b))
{"field_foo":"value"} {"field_foo":"value"}
{"field_foo":"value"} {"field_bar":"value"}
Phew. Good catch.
Fix coming shortly.
Description
Json encoding the same struct twice with different tags does not work, first tag is used for second encode as well.
Version: v1.1.1
Test case
Got
Expected