You've already forked json-iterator
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user