1
0
mirror of https://github.com/json-iterator/go.git synced 2025-04-01 21:24:21 +02:00

fix #202 #203 #204 map encoder not proplery initialized

This commit is contained in:
Tao Wen 2017-12-08 21:18:59 +08:00
parent b2a706d14b
commit d2a7335211

View File

@ -476,7 +476,7 @@ func createEncoderOfType(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error
return &jsoniterNumberCodec{}, nil return &jsoniterNumberCodec{}, nil
} }
if typ.Implements(marshalerType) { if typ.Implements(marshalerType) {
checkIsEmpty, err := createCheckIsEmpty(typ) checkIsEmpty, err := createCheckIsEmpty(cfg, typ)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -491,7 +491,7 @@ func createEncoderOfType(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error
return encoder, nil return encoder, nil
} }
if reflect.PtrTo(typ).Implements(marshalerType) { if reflect.PtrTo(typ).Implements(marshalerType) {
checkIsEmpty, err := createCheckIsEmpty(reflect.PtrTo(typ)) checkIsEmpty, err := createCheckIsEmpty(cfg, reflect.PtrTo(typ))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -503,7 +503,7 @@ func createEncoderOfType(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error
return encoder, nil return encoder, nil
} }
if typ.Implements(textMarshalerType) { if typ.Implements(textMarshalerType) {
checkIsEmpty, err := createCheckIsEmpty(typ) checkIsEmpty, err := createCheckIsEmpty(cfg, typ)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -526,7 +526,7 @@ func createEncoderOfType(cfg *frozenConfig, typ reflect.Type) (ValEncoder, error
return createEncoderOfSimpleType(cfg, typ) return createEncoderOfSimpleType(cfg, typ)
} }
func createCheckIsEmpty(typ reflect.Type) (checkIsEmpty, error) { func createCheckIsEmpty(cfg *frozenConfig, typ reflect.Type) (checkIsEmpty, error) {
kind := typ.Kind() kind := typ.Kind()
switch kind { switch kind {
case reflect.String: case reflect.String:
@ -571,7 +571,7 @@ func createCheckIsEmpty(typ reflect.Type) (checkIsEmpty, error) {
case reflect.Slice: case reflect.Slice:
return &sliceEncoder{}, nil return &sliceEncoder{}, nil
case reflect.Map: case reflect.Map:
return &mapEncoder{}, nil return encoderOfMap(cfg, typ)
case reflect.Ptr: case reflect.Ptr:
return &OptionalEncoder{}, nil return &OptionalEncoder{}, nil
default: default: