Я создаю сообщение json и пытаюсь сделать его совместимым с avro. Вот пример сообщения, которое я хочу отправить, но я получаю следующую ошибку. Думаю, это связано с тем, что схема не соответствует данным, но может быть ошибочной. Я использую KafkaAvroSerializer.class.getName () для сериализатора значений.
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
}
}
}
Вот схема, которую я написал
{
"type": "record",
"namespace": "com.lm.gde.eventing.avro",
"name": "EnrichedPolicyEventAvro",
"version": "1",
"fields": [{
"name": "eventType",
"type": "string"
},
{
"name": "correlationId",
"type": "string"
},
{
"name": "timestamp",
"type": "long"
},
{
"name": "policy",
"type": {
"type": "record",
"name": "PolicyAvro",
"fields": [{
"name": "policyNumber",
"type": "string"
},
{
"name": "policyId",
"type": "string"
},
{
"name": "customerNumber",
"type": "string"
},
{
"name": "effectiveDate",
"type": "string"
},
{
"name": "expirationDate",
"type": "string"
},
{
"name": "transactionEffectiveDate",
"type": "string"
},
{
"name": "revisionNumber",
"type": "string"
},
{
"name": "policyStatusCd",
"type": "string"
},
{
"name": "previousPolicyVersionId",
"type": "string"
},
{
"name": "transactionTypeCd",
"type": "string"
},
{
"name": "vehicles",
"type": {
"type": "array",
"items": {
"name": "vehicles",
"type": "record",
"fields":[
{
"name": "registrationNo",
"type": "string"
},
{
"name": "make",
"type": "string"
},
{
"name": "model",
"type": "string"
},
{
"name": "coverages",
"type": {
"type": "record",
"name": "coverages",
"fields": [{
"name": "roadAssistanceCoverLevelCd",
"type": "string"
}]
}
}
]
}
}
},
{
"name": "customer",
"type": {
"type": "record",
"name": "customer",
"fields": [{
"name": "extensionFields",
"type": {
"type": "record",
"name": "extensionFields",
"fields": [{
"name": "nif",
"type": "string"
}]
}
},
{
"name": "individualDetails",
"type": {
"type": "record",
"name": "individualDetails",
"fields": [{
"name": "firstName",
"type": "string"
},
{
"name": "lastName",
"type": "string"
}
]
}
},
{
"name": "phones",
"type": {
"type": "array",
"items": {
"name": "phoneNumber",
"type": "record",
"fields":[
{
"name": "phoneNumber",
"type": "string"
}
]
}
}
},
{
"name": "addresses",
"type": {
"type": "array",
"items": {
"name": "address",
"type": "record",
"fields":[
{
"name": "addressLine1",
"type": "string"
},
{
"name": "addressLine2",
"type": "string"
},
{
"name": "addressLine3",
"type": "string"
},
{
"name": "city",
"type": "string"
},
{
"name": "postalCode",
"type": "string"
}
]
}
}
}
]
}
},
{
"name": "previous_policy",
"type": {
"type": "record",
"name": "previous_policy",
"fields": [{
"name": "vehicles",
"type": {
"type": "array",
"items": {
"name": "VehiclesPreviousPolicy",
"type": "record",
"fields": [{
"name": "registrationNo",
"type": "string"
},
{
"name": "coverages",
"type": {
"type": "record",
"name": "CoveragesPreviousPolicy",
"fields": [{
"name": "roadAssistanceCoverLevelCd",
"type": "string"
}]
}
}
]
}
}
},
{
"name": "policyNumber",
"type": "string"
},
{
"name": "policyId",
"type": "string"
},
{
"name": "customerNumber",
"type": "string"
},
{
"name": "effectiveDate",
"type": "string"
},
{
"name": "expirationDate",
"type": "string"
},
{
"name": "transactionEffectiveDate",
"type": "string"
},
{
"name": "policyStatusCd",
"type": "string"
},
{
"name": "transactionTypeCd",
"type": "string"
},
{
"name": "revisionNumber",
"type": "string"
},
{
"name": "previousPolicyVersionId",
"type": "string"
}
]
}
}
]
}
}
]
}