badjson: Fix Listable

This commit is contained in:
世界 2024-11-07 21:16:56 +08:00
parent c80c8f907c
commit b5f9e70ffd
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -1,6 +1,8 @@
package badoption package badoption
import ( import (
"context"
E "github.com/sagernet/sing/common/exceptions" E "github.com/sagernet/sing/common/exceptions"
"github.com/sagernet/sing/common/json" "github.com/sagernet/sing/common/json"
) )
@ -15,13 +17,13 @@ func (l Listable[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(arrayList) return json.Marshal(arrayList)
} }
func (l *Listable[T]) UnmarshalJSON(content []byte) error { func (l *Listable[T]) UnmarshalJSONContext(ctx context.Context, content []byte) error {
err := json.UnmarshalDisallowUnknownFields(content, (*[]T)(l)) err := json.UnmarshalContextDisallowUnknownFields(ctx, content, (*[]T)(l))
if err == nil { if err == nil {
return nil return nil
} }
var singleItem T var singleItem T
newError := json.UnmarshalDisallowUnknownFields(content, &singleItem) newError := json.UnmarshalContextDisallowUnknownFields(ctx, content, &singleItem)
if newError != nil { if newError != nil {
return E.Errors(err, newError) return E.Errors(err, newError)
} }