mirror of
https://gitee.com/johng/gf
synced 2026-07-06 13:42:46 +08:00
fix: doMapConvertForMapOrStructValue Struct Marshaler
This commit is contained in:
@ -289,6 +289,10 @@ func doMapConvertForMapOrStructValue(in doMapConvertForMapOrStructValueInput) in
|
||||
|
||||
case reflect.Struct:
|
||||
var dataMap = make(map[string]interface{})
|
||||
if _, ok := reflectValue.Interface().(Marshaler); ok {
|
||||
dataMap[reflectValue.Type().Name()] = reflectValue.Interface()
|
||||
return dataMap
|
||||
}
|
||||
// Map converting interface check.
|
||||
if v, ok := in.Value.(iMapStrAny); ok {
|
||||
// Value copy, in case of concurrent safety.
|
||||
|
||||
@ -632,6 +632,15 @@ func (i Issue3108String) MarshalJSON() ([]byte, error) {
|
||||
}
|
||||
|
||||
func Test_Issue3108(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
obj := &Issue3108String{Name: "test"}
|
||||
|
||||
converted := gconv.MapDeep(obj)
|
||||
jsonData, err := json.Marshal(converted)
|
||||
|
||||
t.AssertNil(err)
|
||||
t.Assert(string(jsonData), `{"Issue3108String":"[test]"}`)
|
||||
})
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
type Issue3108 struct {
|
||||
MyName Issue3108String `json:"my_name"`
|
||||
|
||||
Reference in New Issue
Block a user