mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-16 00:06:55 +00:00
Merge pull request #119883 from ls-2018/json
Fix: null jsonpath serialization Kubernetes-commit: c5a8015bbae1e1095813d8e0719f017477dc7112
This commit is contained in:
commit
c1466acf62
@ -573,6 +573,9 @@ func (j *JSONPath) evalToText(v reflect.Value) ([]byte, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("can't print type %s", v.Type())
|
||||
}
|
||||
if iface == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
var buffer bytes.Buffer
|
||||
fmt.Fprint(&buffer, iface)
|
||||
return buffer.Bytes(), nil
|
||||
|
@ -301,7 +301,8 @@ func TestJSONInput(t *testing.T) {
|
||||
{"id": "i3", "x": 8, "y": 3 },
|
||||
{"id": "i4", "x": -6, "y": -1 },
|
||||
{"id": "i5", "x": 0, "y": 2, "z": 1 },
|
||||
{"id": "i6", "x": 1, "y": 4 }
|
||||
{"id": "i6", "x": 1, "y": 4 },
|
||||
{"id": "i7", "x": null, "y": 4 }
|
||||
]`)
|
||||
var pointsData interface{}
|
||||
err := json.Unmarshal(pointsJSON, &pointsData)
|
||||
@ -311,6 +312,7 @@ func TestJSONInput(t *testing.T) {
|
||||
pointsTests := []jsonpathTest{
|
||||
{"exists filter", "{[?(@.z)].id}", pointsData, "i2 i5", false},
|
||||
{"bracket key", "{[0]['id']}", pointsData, "i1", false},
|
||||
{"nil value", "{[-1]['x']}", pointsData, "null", false},
|
||||
}
|
||||
testJSONPath(pointsTests, false, t)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user