fix: error handling

This commit is contained in:
septs 2023-10-08 11:32:50 +08:00
parent 39dbb8c156
commit 0c47e2c0c2
No known key found for this signature in database
GPG Key ID: 65144037AFA516E1

View File

@ -94,8 +94,9 @@ func (l Listable[T]) MarshalJSON() ([]byte, error) {
func (l *Listable[T]) UnmarshalJSON(content []byte) (err error) {
if len(content) > 0 && content[0] != '[' {
var element T
err = json.Unmarshal(content, &element)
if err = json.Unmarshal(content, &element); err == nil {
*l = []T{element}
}
return
}
return json.Unmarshal(content, (*[]T)(l))