Improve usages of json.Unmarshal

This commit is contained in:
世界
2024-07-22 12:10:22 +08:00
parent 9b8d6c1b73
commit f4f5a3c925
3 changed files with 4 additions and 8 deletions

View File

@@ -128,12 +128,12 @@ func (l Listable[T]) MarshalJSON() ([]byte, error) {
}
func (l *Listable[T]) UnmarshalJSON(content []byte) error {
err := json.Unmarshal(content, (*[]T)(l))
err := json.UnmarshalDisallowUnknownFields(content, (*[]T)(l))
if err == nil {
return nil
}
var singleItem T
newError := json.Unmarshal(content, &singleItem)
newError := json.UnmarshalDisallowUnknownFields(content, &singleItem)
if newError != nil {
return E.Errors(err, newError)
}