mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-02 03:17:37 +03:00
badjson: Fix Listable
This commit is contained in:
parent
c80c8f907c
commit
b5f9e70ffd
1 changed files with 5 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
|||
package badoption
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
"github.com/sagernet/sing/common/json"
|
||||
)
|
||||
|
@ -15,13 +17,13 @@ func (l Listable[T]) MarshalJSON() ([]byte, error) {
|
|||
return json.Marshal(arrayList)
|
||||
}
|
||||
|
||||
func (l *Listable[T]) UnmarshalJSON(content []byte) error {
|
||||
err := json.UnmarshalDisallowUnknownFields(content, (*[]T)(l))
|
||||
func (l *Listable[T]) UnmarshalJSONContext(ctx context.Context, content []byte) error {
|
||||
err := json.UnmarshalContextDisallowUnknownFields(ctx, content, (*[]T)(l))
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
var singleItem T
|
||||
newError := json.UnmarshalDisallowUnknownFields(content, &singleItem)
|
||||
newError := json.UnmarshalContextDisallowUnknownFields(ctx, content, &singleItem)
|
||||
if newError != nil {
|
||||
return E.Errors(err, newError)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue