We have a bug in the current enum rendering system where the MarshalJSON method is never called on pointer structs. This fixes this behavior (quiet easily).
import (
"encoding/json"
"fmt"
)
type Enum struct {
value string
}
type Enum2 struct {
valie string
}
func (e Enum) MarshalJSON() ([]byte, error) {
return []byte("\"another_value\""), nil
}
func (e *Enum2) MarshalJSON() ([]byte, error) {
return []byte("\"another_value\""), nil
}
type Test struct {
A Enum
C Enum2
B int
}
func main() {
x := Test{
A: Enum{},
C: Enum2{},
B: 1,
}
j, err := json.Marshal(x)
if err != nil {
panic(err)
}
fmt.Println(string(j))
}
We have a bug in the current enum rendering system where the MarshalJSON method is never called on pointer structs. This fixes this behavior (quiet easily).
Prints:
Go playground example: https://go.dev/play/p/8QQzFwO9a-K