(experimental) upgraded to encoding/json/v2

This commit is contained in:
Gani Georgiev committed 2026-08-18 18:16:22 +03:00
1 parent 4d4275c9aa
commit 97dd775455
125 files changed
+433 -364

No files matched your search

+6 -3
View File
@@ -1,7 +1,7 @@
package fileblob
import (
"encoding/json"
"encoding/json/v2"
"fmt"
"os"
)
@@ -50,7 +50,8 @@ func setAttrs(path string, xa xattrs) error {
return err
}
if err := json.NewEncoder(f).Encode(xa); err != nil {
err = json.MarshalWrite(f, xa)
if err != nil {
f.Close()
os.Remove(f.Name())
return err
@@ -75,7 +76,9 @@ func getAttrs(path string) (xattrs, error) {
}
xa := new(xattrs)
if err := json.NewDecoder(f).Decode(xa); err != nil {
err = json.UnmarshalRead(f, xa)
if err != nil {
f.Close()
return xattrs{}, err
}
@@ -1,7 +1,7 @@
package s3_test
import (
"encoding/json"
"encoding/json/v2"
"encoding/xml"
"testing"
@@ -29,7 +29,7 @@ func TestResponseErrorSerialization(t *testing.T) {
t.Fatal(err)
}
jsonRaw, err := json.Marshal(respErr)
jsonRaw, err := json.Marshal(respErr, json.Deterministic(true))
if err != nil {
t.Fatal(err)
}
@@ -2,7 +2,7 @@ package s3_test
import (
"context"
"encoding/json"
"encoding/json/v2"
"io"
"net/http"
"strings"
@@ -78,7 +78,7 @@ func TestS3GetObject(t *testing.T) {
}
// check serialized attributes
raw, err := json.Marshal(resp)
raw, err := json.Marshal(resp, json.Deterministic(true))
if err != nil {
t.Fatal(err)
}
@@ -2,7 +2,7 @@ package s3_test
import (
"context"
"encoding/json"
"encoding/json/v2"
"net/http"
"testing"
@@ -63,7 +63,7 @@ func TestS3HeadObject(t *testing.T) {
t.Fatal(err)
}
raw, err := json.Marshal(resp)
raw, err := json.Marshal(resp, json.Deterministic(true))
if err != nil {
t.Fatal(err)
}
@@ -2,7 +2,7 @@ package s3_test
import (
"context"
"encoding/json"
"encoding/json/v2"
"io"
"net/http"
"strings"
@@ -143,7 +143,7 @@ func TestS3ListObjects(t *testing.T) {
t.Fatal(err)
}
raw, err := json.Marshal(resp)
raw, err := json.Marshal(resp, json.Deterministic(true))
if err != nil {
t.Fatal(err)
}
@@ -2,7 +2,7 @@ package s3blob_test
import (
"context"
"encoding/json"
"encoding/json/v2"
"errors"
"fmt"
"io"
@@ -261,7 +261,11 @@ func TestDriverAttributes(t *testing.T) {
t.Fatal(err)
}
raw, err := json.Marshal(attrs)
raw, err := json.Marshal(
attrs,
json.Deterministic(true),
json.FormatNilSliceAsNull(true),
)
if err != nil {
t.Fatal(err)
}
@@ -362,7 +366,11 @@ func TestDriverListPaged(t *testing.T) {
t.Fatal(err)
}
raw, err := json.Marshal(page)
raw, err := json.Marshal(
page,
json.Deterministic(true),
json.FormatNilSliceAsNull(true),
)
if err != nil {
t.Fatal(err)
}
@@ -510,7 +518,11 @@ func TestDriverNewRangeReader(t *testing.T) {
}
}
rawAttrs, err := json.Marshal(r.Attributes())
rawAttrs, err := json.Marshal(
r.Attributes(),
json.Deterministic(true),
json.FormatNilSliceAsNull(true),
)
if err != nil {
t.Fatal(err)
}