1
0
mirror of https://github.com/json-iterator/go.git synced 2025-11-29 22:47:28 +02:00

Fix custom marshaler for enum types

When MarshalJSON was defined on a pointer receiver custom enum type
marshaling/unmarshaling was panicing since the underlying primitive type
was treated as a pointer.

Since method set for pointer receivers includes value receiver methods
we don't really need optionalEncoder and can just use marshalEncoder
directly.
This commit is contained in:
Oleg Shaldybin
2017-09-14 23:04:54 -07:00
parent eef35e549b
commit ae57d167e8
3 changed files with 51 additions and 1 deletions

View File

@@ -661,6 +661,7 @@ func (encoder *marshalerEncoder) Encode(ptr unsafe.Pointer, stream *Stream) {
templateInterface.word = ptr
realInterface := (*interface{})(unsafe.Pointer(&templateInterface))
marshaler := (*realInterface).(json.Marshaler)
bytes, err := marshaler.MarshalJSON()
if err != nil {
stream.Error = err