diff --git a/Makefile b/Makefile index 18c6687..1604dfa 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ generate: root build .root/src/$(PKG)/tests/named_type.go \ .root/src/$(PKG)/tests/custom_map_key_type.go \ .root/src/$(PKG)/tests/embedded_type.go \ - .root/src/$(PKG)/tests/reference_to_pointer.go + .root/src/$(PKG)/tests/reference_to_pointer.go \ .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go @@ -39,6 +39,7 @@ generate: root build .root/bin/easyjson .root/src/$(PKG)/tests/custom_map_key_type.go .root/bin/easyjson .root/src/$(PKG)/tests/embedded_type.go .root/bin/easyjson .root/src/$(PKG)/tests/reference_to_pointer.go + .root/bin/easyjson .root/src/$(PKG)/tests/key_marshaler_map.go .root/bin/easyjson -disallow_unknown_fields .root/src/$(PKG)/tests/disallow_unknown.go test: generate root diff --git a/tests/basic_test.go b/tests/basic_test.go index 3b1cc65..938add0 100644 --- a/tests/basic_test.go +++ b/tests/basic_test.go @@ -52,6 +52,7 @@ var testCases = []struct { {&intArrayStructValue, intArrayStructValueString}, {&myUInt8SliceValue, myUInt8SliceString}, {&myUInt8ArrayValue, myUInt8ArrayString}, + {&mapWithEncodingMarshaler, mapWithEncodingMarshalerString}, } func TestMarshal(t *testing.T) { diff --git a/tests/key_marshaler_map.go b/tests/key_marshaler_map.go new file mode 100644 index 0000000..e10421a --- /dev/null +++ b/tests/key_marshaler_map.go @@ -0,0 +1,20 @@ +package tests + +type KeyWithEncodingMarshaler int + +func (f KeyWithEncodingMarshaler) MarshalText() (text []byte, err error) { + return []byte("hello"), nil +} + +func (f *KeyWithEncodingMarshaler) UnmarshalText(text []byte) error { + if string(text) == "hello" { + *f = 5 + } + return nil +} + +//easyjson:json +type KeyWithEncodingMarshalers map[KeyWithEncodingMarshaler]string + +var mapWithEncodingMarshaler KeyWithEncodingMarshalers = KeyWithEncodingMarshalers{5: "hello"} +var mapWithEncodingMarshalerString = `{"hello":"hello"}`