Skip to content

Commit 3c9309d

Browse files
committed
drop deprecated json/yaml newSerializers, use json.NewSerializerWithOptions instead
Signed-off-by: liyuerich <[email protected]>
1 parent 2d8a3ad commit 3c9309d

File tree

13 files changed

+23
-23
lines changed

13 files changed

+23
-23
lines changed

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/customresource_handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,14 +858,14 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
858858
MediaTypeType: "application",
859859
MediaTypeSubType: "json",
860860
EncodesAsText: true,
861-
Serializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, false),
862-
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, true),
861+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{}),
862+
PrettySerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{Pretty: true}),
863863
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
864864
Strict: true,
865865
}),
866866
StreamSerializer: &runtime.StreamSerializerInfo{
867867
EncodesAsText: true,
868-
Serializer: json.NewSerializer(json.DefaultMetaFactory, creator, typer, false),
868+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{}),
869869
Framer: json.Framer,
870870
},
871871
},
@@ -874,7 +874,7 @@ func (r *crdHandler) getOrCreateServingInfoFor(uid types.UID, name string) (*crd
874874
MediaTypeType: "application",
875875
MediaTypeSubType: "yaml",
876876
EncodesAsText: true,
877-
Serializer: json.NewYAMLSerializer(json.DefaultMetaFactory, creator, typer),
877+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{Yaml: true}),
878878
StrictSerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, creator, typer, json.SerializerOptions{
879879
Yaml: true,
880880
Strict: true,

staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/objectmeta/coerce_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
func TestRoundtripObjectMeta(t *testing.T) {
3939
scheme := runtime.NewScheme()
4040
codecs := serializer.NewCodecFactory(scheme)
41-
codec := json.NewSerializer(json.DefaultMetaFactory, scheme, scheme, false)
41+
codec := json.NewSerializerWithOptions(json.DefaultMetaFactory, scheme, scheme, json.SerializerOptions{})
4242
seed := rand.Int63()
4343
fuzzer := fuzzer.FuzzerFor(metafuzzer.Funcs, rand.NewSource(seed), codecs)
4444

staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/compatibility.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func (c *CompatibilityTestOptions) Complete(t *testing.T) *CompatibilityTestOpti
181181
}
182182

183183
if c.JSON == nil {
184-
c.JSON = json.NewSerializer(json.DefaultMetaFactory, c.Scheme, c.Scheme, true)
184+
c.JSON = json.NewSerializerWithOptions(json.DefaultMetaFactory, c.Scheme, c.Scheme, json.SerializerOptions{Pretty: true})
185185
}
186186
if c.YAML == nil {
187-
c.YAML = json.NewYAMLSerializer(json.DefaultMetaFactory, c.Scheme, c.Scheme)
187+
c.YAML = json.NewSerializerWithOptions(json.DefaultMetaFactory, c.Scheme, c.Scheme, json.SerializerOptions{Yaml: true})
188188
}
189189
if c.Proto == nil {
190190
c.Proto = protobuf.NewSerializer(c.Scheme, c.Scheme)

staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/roundtrip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func roundTripOfExternalType(t *testing.T, scheme *runtime.Scheme, codecFactory
279279
typeAcc.SetKind(externalGVK.Kind)
280280
typeAcc.SetAPIVersion(externalGVK.GroupVersion().String())
281281

282-
roundTrip(t, scheme, json.NewSerializer(json.DefaultMetaFactory, scheme, scheme, false), object)
282+
roundTrip(t, scheme, json.NewSerializerWithOptions(json.DefaultMetaFactory, scheme, scheme, json.SerializerOptions{}), object)
283283

284284
// TODO remove this hack after we're past the intermediate steps
285285
if !skipProtobuf {

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/unstructured/unstructuredscheme/scheme.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ func (s unstructuredNegotiatedSerializer) SupportedMediaTypes() []runtime.Serial
5050
MediaTypeType: "application",
5151
MediaTypeSubType: "json",
5252
EncodesAsText: true,
53-
Serializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, false),
54-
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, true),
53+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{}),
54+
PrettySerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{Pretty: true}),
5555
StreamSerializer: &runtime.StreamSerializerInfo{
5656
EncodesAsText: true,
57-
Serializer: json.NewSerializer(json.DefaultMetaFactory, s.creator, s.typer, false),
57+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{}),
5858
Framer: json.Framer,
5959
},
6060
},
@@ -63,7 +63,7 @@ func (s unstructuredNegotiatedSerializer) SupportedMediaTypes() []runtime.Serial
6363
MediaTypeType: "application",
6464
MediaTypeSubType: "yaml",
6565
EncodesAsText: true,
66-
Serializer: json.NewYAMLSerializer(json.DefaultMetaFactory, s.creator, s.typer),
66+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, s.creator, s.typer, json.SerializerOptions{Yaml: true}),
6767
},
6868
}
6969
}

staging/src/k8s.io/apimachinery/pkg/runtime/serializer/json/json_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ func TestCacheableObject(t *testing.T) {
905905
gvk := schema.GroupVersionKind{Group: "group", Version: "version", Kind: "MockCacheableObject"}
906906
creater := &mockCreater{obj: &runtimetesting.MockCacheableObject{}}
907907
typer := &mockTyper{gvk: &gvk}
908-
serializer := json.NewSerializer(json.DefaultMetaFactory, creater, typer, false)
908+
serializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, creater, typer, json.SerializerOptions{})
909909

910910
runtimetesting.CacheableObjectTest(t, serializer)
911911
}

staging/src/k8s.io/apimachinery/pkg/runtime/serializer/recognizer/testing/recognizer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func TestRecognizer(t *testing.T) {
3636
s := runtime.NewScheme()
3737
s.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &A{})
3838
d := recognizer.NewDecoder(
39-
json.NewSerializer(json.DefaultMetaFactory, s, s, false),
40-
json.NewYAMLSerializer(json.DefaultMetaFactory, s, s),
39+
json.NewSerializerWithOptions(json.DefaultMetaFactory, s, s, json.SerializerOptions{}),
40+
json.NewSerializerWithOptions(json.DefaultMetaFactory, s, s, json.SerializerOptions{Yaml: true}),
4141
)
4242
out, _, err := d.Decode([]byte(`
4343
kind: A

staging/src/k8s.io/apiserver/pkg/admission/plugin/webhook/mutating/dispatcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (a *mutatingDispatcher) callAttrMutatingHook(ctx context.Context, h *admiss
348348
}
349349

350350
var patchedJS []byte
351-
jsonSerializer := json.NewSerializer(json.DefaultMetaFactory, o.GetObjectCreater(), o.GetObjectTyper(), false)
351+
jsonSerializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, o.GetObjectCreater(), o.GetObjectTyper(), json.SerializerOptions{})
352352
switch result.PatchType {
353353
// VerifyAdmissionResponse normalizes to v1 patch types, regardless of the AdmissionReview version used
354354
case admissionv1.PatchTypeJSONPatch:

staging/src/k8s.io/apiserver/plugin/pkg/audit/webhook/webhook_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import (
4545
// request body. The caller passes a callback which is called on each webhook POST.
4646
// The object passed to cb is of the same type as list.
4747
func newWebhookHandler(t *testing.T, list runtime.Object, cb func(events runtime.Object)) http.Handler {
48-
s := json.NewSerializer(json.DefaultMetaFactory, audit.Scheme, audit.Scheme, false)
48+
s := json.NewSerializerWithOptions(json.DefaultMetaFactory, audit.Scheme, audit.Scheme, json.SerializerOptions{})
4949
return &testWebhookHandler{
5050
t: t,
5151
list: list,

staging/src/k8s.io/client-go/dynamic/scheme.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ func (s basicNegotiatedSerializer) SupportedMediaTypes() []runtime.SerializerInf
5151
MediaTypeType: "application",
5252
MediaTypeSubType: "json",
5353
EncodesAsText: true,
54-
Serializer: json.NewSerializer(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, false),
55-
PrettySerializer: json.NewSerializer(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, true),
54+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, json.SerializerOptions{}),
55+
PrettySerializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, unstructuredCreater{basicScheme}, unstructuredTyper{basicScheme}, json.SerializerOptions{Pretty: true}),
5656
StreamSerializer: &runtime.StreamSerializerInfo{
5757
EncodesAsText: true,
58-
Serializer: json.NewSerializer(json.DefaultMetaFactory, basicScheme, basicScheme, false),
58+
Serializer: json.NewSerializerWithOptions(json.DefaultMetaFactory, basicScheme, basicScheme, json.SerializerOptions{}),
5959
Framer: json.Framer,
6060
},
6161
},

0 commit comments

Comments
 (0)