BUG记录:使用fastjson反序列化V1Job失败
String jobsList:
{
"kind": "List",
"apiVersion": "batch/v1",
"metadata": {
"selfLink": "/apis/batch/v1/namespaces/networkcheck/jobs",
"resourceVersion": "264369664"
},
"items": [
{
"kind": "Job",
"apiVersion": "batch/v1",
"metadata": {
"name": "sit102-shiyishi1",
"namespace": "networkcheck",
"selfLink": "/apis/batch/v1/namespaces/networkcheck/jobs/sit102-shiyishi1",
"uid": "9b72c659-da37-4725-a516-6efeab65561f",
"resourceVersion": "254040100",
"creationTimestamp": "2022-09-30T08:36:49Z",
"labels": {
"job-name": "sit102-shiyishi1"
}
},
"spec": {
"parallelism": 1,
"completions": 1,
"backoffLimit": 6,
"selector": {
"matchLabels": {
"controller-uid": "9b72c659-da37-4725-a516-6efeab65561f",
"job-name": "sit102-shiyishi1"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"controller-uid": "9b72c659-da37-4725-a516-6efeab65561f",
"job-name": "sit102-shiyishi1"
},
"annotations": {
"dce.daocloud.io/parcel.net.type": "ovs",
"dce.daocloud.io/parcel.net.value": "rule:vlan154-:shiyishi"
}
},
"spec": {
"containers": [
{
"name": "check",
"image": "168.63.124.14/000369/network-check:v0.1",
"command": [
"/bin/sh",
"-c",
"sleep 1m"
],
"resources": {
"limits": {
"cpu": "500m",
"memory": "500Mi"
},
"requests": {
"cpu": "500m",
"memory": "500Mi"
}
},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "IfNotPresent"
}
],
"restartPolicy": "Never",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"schedulerName": "default-scheduler"
}
}
},
"status": {
"conditions": [
{
"type": "Complete",
"status": "True",
"lastProbeTime": "2022-09-30T08:38:01Z",
"lastTransitionTime": "2022-09-30T08:38:01Z"
}
],
"startTime": "2022-09-30T08:36:49Z",
"completionTime": "2022-09-30T08:38:01Z",
"succeeded": 1
}
},
{
"kind": "Job",
"apiVersion": "batch/v1",
"metadata": {
"name": "sit102-shiyishi2",
"namespace": "networkcheck",
"selfLink": "/apis/batch/v1/namespaces/networkcheck/jobs/sit102-shiyishi2",
"uid": "1e90bd4f-f2e5-49af-8dbe-08453499c09d",
"resourceVersion": "254043174",
"creationTimestamp": "2022-09-30T08:41:59Z",
"labels": {
"job-name": "sit102-shiyishi2"
}
},
"spec": {
"parallelism": 1,
"completions": 1,
"backoffLimit": 6,
"selector": {
"matchLabels": {
"controller-uid": "1e90bd4f-f2e5-49af-8dbe-08453499c09d",
"job-name": "sit102-shiyishi2"
}
},
"template": {
"metadata": {
"creationTimestamp": null,
"labels": {
"controller-uid": "1e90bd4f-f2e5-49af-8dbe-08453499c09d",
"job-name": "sit102-shiyishi2"
},
"annotations": {
"dce.daocloud.io/parcel.net.type": "ovs",
"dce.daocloud.io/parcel.net.value": "rule:vlan154-:shiyishi"
}
},
"spec": {
"containers": [
{
"name": "check",
"image": "168.63.124.14/000369/network-check:v0.1",
"command": [
"/bin/sh",
"-c",
"sleep 999d"
],
"resources": {
"limits": {
"cpu": "500m",
"memory": "500Mi"
},
"requests": {
"cpu": "500m",
"memory": "500Mi"
}
},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"imagePullPolicy": "IfNotPresent"
}
],
"restartPolicy": "Never",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {},
"schedulerName": "default-scheduler"
}
}
},
"status": {
"startTime": "2022-09-30T08:41:59Z",
"active": 1
}
}
]
}
用以下代码解析其中的items字段,会报错误 com.alibaba.fastjson.JSONException: syntax error,except start with { or [,but actually start with string
V1JobList v1JobList = Codecs.jsonStrToObj(jobsList, V1JobList.class); // 无法直接解析,会有不明错误
debug发现是resources字段无法解析,原因不明
准备换成gson进行反序列化
浙公网安备 33010602011771号