Skip to content

Commit 00212a4

Browse files
committed
fix: don't dereference pointer if MarshalJSON expects a pointer
1 parent 9872089 commit 00212a4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

encode_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,3 +2715,28 @@ func TestIssue441(t *testing.T) {
27152715
assertErr(t, err)
27162716
assertEq(t, "unexpected result", "{}", string(b))
27172717
}
2718+
2719+
type Map map[string]struct{}
2720+
2721+
type MapMap map[string]Map
2722+
2723+
func (m Map) MarshalJSON() ([]byte, error) {
2724+
keys := make([]string, 0, len(m))
2725+
for k := range m {
2726+
keys = append(keys, k)
2727+
}
2728+
return json.Marshal(keys)
2729+
}
2730+
2731+
func TestMapType(t *testing.T) {
2732+
v := MapMap{
2733+
"test": Map{
2734+
"test": {},
2735+
},
2736+
}
2737+
b, err := json.Marshal(v)
2738+
if err != nil {
2739+
t.Fatal(err)
2740+
}
2741+
assertEq(t, "unexpected result", `{"test":["test"]}`, string(b))
2742+
}

internal/encoder/vm/vm.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)