@@ -11,8 +11,8 @@ import (
11
11
"strings"
12
12
13
13
"github.com/antlabs/gstl/mapex"
14
- "github.com/antlabs/tostruct/internal/name"
15
14
"github.com/antlabs/tostruct/internal/tab"
15
+ "github.com/antlabs/tostruct/name"
16
16
"github.com/antlabs/tostruct/option"
17
17
)
18
18
@@ -254,10 +254,6 @@ func (f *JSON) marshalMap(key string, m map[string]interface{}, typePrefix strin
254
254
}
255
255
256
256
func (f * JSON ) marshalArray (key string , a []interface {}, depth int , buf * bytes.Buffer , keyPath string ) {
257
- if len (a ) == 0 {
258
- buf .WriteString (fmt .Sprintf ("%s interface{} `json:\" json:%s\" `" , key , key ))
259
- return
260
- }
261
257
262
258
f .marshalValue (key , a [0 ], true , depth , buf , keyPath )
263
259
}
@@ -287,6 +283,10 @@ func (f *JSON) marshalValue(key string, obj interface{}, fromArray bool, depth i
287
283
case map [string ]interface {}:
288
284
f .marshalMap (key , v , typePrefix , depth , buf , keyPath )
289
285
case []interface {}:
286
+ if len (v ) == 0 {
287
+ buf .WriteString (fmt .Sprintf ("%s interface{} `json:\" %s\" `" , fieldName , key ))
288
+ return
289
+ }
290
290
f .marshalArray (key , v , depth , buf , keyPath + "[0]" )
291
291
case string :
292
292
buf .WriteString (fmt .Sprintf (stringFmt , fieldName , typePrefix , f .Tag , tagName ))
0 commit comments