Avro模式不符合我的json数据?

时间:2019-11-04 12:56:14

标签: json apache-kafka schema avro confluent

我正在生成json消息,并尝试使其符合Avro标准。这是我要发送的消息的示例,但是我收到以下错误,我认为这是由于架构不匹配数据,但可能是错误的,我将KafkaAvroSerializer.class.getName()用于值序列化程序

Point[] hull; Point[][] contours; for (int i = 0; i < contours.Length; i++) { hull = Cv2.ConvexHull(contours[i], false); defects = Cv2.ConvexityDefects(contours[i], hull); Cv2.DrawContours(frame, new Point[][] { hull }, (int)largestContour, new OpenCvSharp.Scalar(0, 0, 255), 2); }

nested exception is org.apache.kafka.common.errors.SerializationException: Error serializing Avro message; nested exception is org.apache.kafka.common.errors.SerializationException: Error serializing Avro message

Caused by: java.lang.NullPointerException: null of string of com.lm.gde.eventing.avro.CoveragesPreviousPolicy of com.lm.gde.eventing.avro.VehiclesPreviousPolicy of array of com.lm.gde.eventing.avro.previous_policy of com.lm.gde.eventing.avro.PolicyAvro of com.lm.gde.eventing.avro.EnrichedPolicyEventAvro

这是我编写的架构

{
    "eventType": "policy.PolicyTxIssueEvent",
    "correlationId": "XXXXXX",
    "timestamp": 1572532310225,
    "policy": {
        "policyNumber": "XXXXXX",
        "policyId": "XXXXXX",
        "customerNumber": "XXXXXX",
        "effectiveDate": "2019-10-26T00:00:00+01:00",
        "expirationDate": "2020-10-25T23:59:00Z",
        "transactionEffectiveDate": "2019-10-31T00:00:00Z",
        "revisionNumber": "2",
        "policyStatusCd": "issued",
        "previousPolicyVersionId": "XXXXXX",
        "transactionTypeCd": "endorsement",
        "vehicles": [{
            "registrationNo": "XXXXXX",
            "make": "XXXXXX",
            "model": "XXXXXX",
            "coverages": {
                "roadAssistanceCoverLevelCd": "Medium"
            }
        }],
        "customer": {
            "extensionFields": {
                "nif": "XXXXXX"
            },
            "individualDetails": {
                "firstName": "XXXXXX",
                "lastName": "XXXXXX"
            },
            "phones": [{
                "phoneNumber": "XXXXXX"
            }],
            "addresses": [{
                "addressLine1": "XXXXXX",
                "addressLine2": "",
                "addressLine3": "",
                "city": "XXXXXX",
                "postalCode": "XXXXXX"
            }]
        },
        "previous_policy": {
            "vehicles": [{
                "registrationNo": "XXXXXX",
                "coverages": {
                    "roadAssistanceCoverLevelCd": null
                }
            }],
            "policyNumber": "XXXXXX",
            "policyId": "XXXXXX",
            "customerNumber": "XXXXXX",
            "effectiveDate": "2019-10-26T00:00:00+01:00",
            "expirationDate": "2020-10-25T23:59:00Z",
            "transactionEffectiveDate": "2019-10-26T00:00:00+01:00",
            "policyStatusCd": "issued",
            "transactionTypeCd": "policy",
            "revisionNumber": "1",
            "previousPolicyVersionId": null
        }
    }
}

1 个答案:

答案 0 :(得分:0)

通过在https://toolslick.com/generation/metadata/avro-schema-from-json此处的在线转换器中发布数据来获得架构