我们有一个需求,通过队列传递JSON字符串,队列有大小限制。是否有可能使用 JSON 模式从 JSON 字符串/对象中删除可选元素,以便它可以放入队列中。
假设以下是一个示例 JSON Schema:
{
"components": {
"schemas": {
"Data": {
"properties": {
"admittedOn": {
"example": "2023-02-20",
"title": "The admittedOn Schema",
"type": "string"
},
"claimAmount": {
"example": 500,
"title": "The claimAmount Schema",
"type": "integer"
},
"clinicName": {
"enum": [
"Mayo Clinic",
"Appollo",
"Care",
"Govt"
],
"example": "Mayo Clinic",
"title": "The clinicName Schema",
"type": "string"
},
"dischargedOn": {
"example": "2023-02-25",
"title": "The dischargedOn Schema",
"type": "string"
},
"firstName": {
"example": "Jon",
"title": "The firstName Schema",
"type": "string"
},
"lastName": {
"example": "Doe",
"title": "The lastName Schema",
"type": "string"
},
"stateCode": {
"example": "MN",
"title": "The state code",
"type": "string"
}
},
"required": [
"firstName",
"lastName",
"admittedOn",
"clinicName"
],
"type": "object"
},
"Event": {
"additionalProperties": false,
"properties": {
"data": {
"$ref": "#/components/schemas/Data"
},
"datacontenttype": {
"type": "string"
},
"dataref": {
"type": "string"
},
"dataschema": {
"type": "string"
},
"environment": {
"pattern": "^[^pP]|^.[^rR]|^..[^oO]|^...[^dD]$",
"type": "string"
},
"id": {
"type": "string"
},
"partitionkey": {
"type": "string"
},
"sampledrate": {
"type": "integer"
},
"sequence": {
"type": "string"
},
"severitynumber": {
"type": "integer"
},
"severitytext": {
"type": "string"
},
"source": {
"pattern": "^[a-zA-Z0-9\\.\\_\\-\\:\\@\\/]*$",
"type": "string"
},
"specversion": {
"enum": [
"1.0"
],
"type": "string"
},
"subject": {
"type": "string"
},
"time": {
"pattern": "^((?:(\\d{4}-\\d{2}-\\d{2})T(\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?))(Z|[\\+-]\\d{2}:\\d{2})?)$",
"type": "string"
},
"traceparent": {
"pattern": "^[\\da-f]{2}-[\\da-f]{32}-[\\da-f]{16}-[\\da-f]{2}$",
"type": "string"
},
"tracestate": {
"pattern": "^([^,]+=[^,]+)(,([^,]+=[^,]+))*?$",
"type": "string"
},
"type": {
"default": "patient.covid.claims.v3.0.0",
"enum": [
"patient.covid.claims.v3.0.0"
],
"pattern": "^[a-zA-Z0-9\\.\\_\\-]*$",
"type": "string"
}
},
"required": [
"data",
"environment",
"id",
"source",
"specversion",
"type"
],
"type": "object"
}
}
}
}
示例 JSON 字符串:
{
"id": "5a54e6ae-b92e-4393-a360-e28376fa7af5",
"type": "patient.covid.claims.v1.0.0",
"source": "myapp",
"specversion": "1.0",
"subject": "Claim request",
"time": "2023-11-06T17:40:18.003Z",
"datacontenttype": "application/json",
"environment": "dev",
"data": {
"firstName": "Myrtie Bowman",
"lastName": "Ethel Harper",
"admittedOn": "2023-02-20",
"dischargedOn": "2023-02-25",
"clinicName": "Mayo Clinic",
"claimAmount": 500,
"stateCode": "MN"
}
}
删除可选值后,预期的 JSON 字符串如下所示:
{
"id": "5a54e6ae-b92e-4393-a360-e28376fa7af5",
"type": "patient.covid.claims.v1.0.0",
"source": "myapp",
"specversion": "1.0",
"environment": "dev",
"data": {
"firstName": "Myrtie Bowman",
"lastName": "Ethel Harper",
"admittedOn": "2023-02-20",
"clinicName": "Mayo Clinic"
}
}
关于如何使用模式定义从 Java 中的 JSON 中删除可选元素有什么想法吗?