client-go version: 0.17.0
I try to serialize the following:
buf := bytes.NewBufferString("")
scheme := runtime.NewScheme()
serializer := json.NewSerializerWithOptions(json.DefaultMetaFactory, scheme, scheme, json.SerializerOptions{
Pretty: true,
Yaml: false,
Strict: true,
})
ar := &admissionv1.AdmissionReview{
Response: &admissionv1.AdmissionResponse{
Allowed: true,
},
}
err := serializer.Encode(ar, buf)
require.NoError(t, err)
fmt.Println(buf.String())
And I get the following result:
{
"response": {
"uid": "",
"allowed": true
}
}
As you can see the TypeMeta is empty.
When I refer to the docs for json.NewSerializerWithOption:
If typer is not nil, the object has the group, version, and kind fields set
As you can see, my typer is not nil, but TypeMeta is not set.
I am not sure what am I missing.