mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
replace ConfigFast with ConfigCompatibleWithStandardLibrary
This commit is contained in:
parent
5da7b11a31
commit
9c17635802
@ -60,22 +60,6 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
}
|
||||
if isValue || c.Intn(10) == 0 {
|
||||
c.Fuzz(vobj.Field(i).Addr().Interface())
|
||||
|
||||
// JSON keys must not contain escape char with our JSON codec (jsoniter)
|
||||
// TODO: remove this when/if we moved from jsoniter.ConfigFastest to ConfigCompatibleWithStandardLibrary
|
||||
if field.Type.Kind() == reflect.Map {
|
||||
keys := append([]reflect.Value(nil), vobj.Field(i).MapKeys()...)
|
||||
for _, k := range keys {
|
||||
stripped := toJSONString(k.String())
|
||||
if stripped == k.String() {
|
||||
continue
|
||||
}
|
||||
// set new key
|
||||
vobj.Field(i).SetMapIndex(reflect.ValueOf(stripped), vobj.Field(i).MapIndex(k))
|
||||
// remove old
|
||||
vobj.Field(i).SetMapIndex(k, reflect.Value{})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -125,13 +109,3 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func toJSONString(s string) string {
|
||||
return strings.Map(func(r rune) rune {
|
||||
// replace chars which are not supported in keys by jsoniter.ConfigFastest
|
||||
if r == '\\' || r == '"' {
|
||||
return 'x'
|
||||
}
|
||||
return r
|
||||
}, s)
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func TestGroupVersionUnmarshalJSON(t *testing.T) {
|
||||
t.Errorf("JSON codec failed to unmarshal input '%s': expected %+v, got %+v", c.input, c.expect, result.GV)
|
||||
}
|
||||
// test the json-iterator codec
|
||||
if err := jsoniter.ConfigFastest.Unmarshal(c.input, &result); err != nil {
|
||||
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(c.input, &result); err != nil {
|
||||
t.Errorf("json-iterator codec failed to unmarshal input '%v': %v", c.input, err)
|
||||
}
|
||||
if !reflect.DeepEqual(result.GV, c.expect) {
|
||||
|
@ -58,7 +58,7 @@ func TestVerbsUgorjiUnmarshalJSON(t *testing.T) {
|
||||
|
||||
for i, c := range cases {
|
||||
var result APIResource
|
||||
if err := jsoniter.ConfigFastest.Unmarshal([]byte(c.input), &result); err != nil {
|
||||
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal([]byte(c.input), &result); err != nil {
|
||||
t.Errorf("[%d] Failed to unmarshal input '%v': %v", i, c.input, err)
|
||||
}
|
||||
if !reflect.DeepEqual(result, c.result) {
|
||||
|
@ -154,7 +154,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
|
||||
types, _, err := s.typer.ObjectKinds(into)
|
||||
switch {
|
||||
case runtime.IsNotRegisteredError(err), isUnstructured:
|
||||
if err := jsoniter.ConfigFastest.Unmarshal(data, into); err != nil {
|
||||
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, into); err != nil {
|
||||
return nil, actual, err
|
||||
}
|
||||
return into, actual, nil
|
||||
@ -188,7 +188,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
|
||||
return nil, actual, err
|
||||
}
|
||||
|
||||
if err := jsoniter.ConfigFastest.Unmarshal(data, obj); err != nil {
|
||||
if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(data, obj); err != nil {
|
||||
return nil, actual, err
|
||||
}
|
||||
return obj, actual, nil
|
||||
@ -197,7 +197,7 @@ func (s *Serializer) Decode(originalData []byte, gvk *schema.GroupVersionKind, i
|
||||
// Encode serializes the provided object to the given writer.
|
||||
func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
||||
if s.yaml {
|
||||
json, err := jsoniter.ConfigFastest.Marshal(obj)
|
||||
json, err := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -210,7 +210,7 @@ func (s *Serializer) Encode(obj runtime.Object, w io.Writer) error {
|
||||
}
|
||||
|
||||
if s.pretty {
|
||||
data, err := jsoniter.ConfigFastest.MarshalIndent(obj, "", " ")
|
||||
data, err := jsoniter.ConfigCompatibleWithStandardLibrary.MarshalIndent(obj, "", " ")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user