首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Avro架构问题-抛出空指针异常,但数据有效

Avro架构问题-抛出空指针异常,但数据有效
EN

Stack Overflow用户
提问于 2020-01-15 01:47:17
回答 1查看 936关注 0票数 0

这是一个正在发送的数据的示例,但由于某种原因,我得到了一个空指针异常,我试图剥离一些代码以使其更小,但我认为我可能需要保留大量的模式来显示格式和嵌套字段。我已编辑为仅显示相关部分,因为不希望在网上宣传我的方案

代码语言:javascript
复制
{
    "eventType": "XXX",
    "correlationId": "XXX",
    "timestamp": XXX,
    "policy": {
        "policyNumber": "XXX",
        "policyId": "XXX",
        "customerNumber": "XXX",
        ......(lots more fields like this)
        "insuredsAndDrivers": [{
            ......(lots more fields )
            "driver": {
                "relationshipToInsuredCd": "IN",
                "driverTypeCd": "P",
                "occupationCd": null,
                "driverLicenses": [{
                    "licenseTypeCd": null,
                    "licenseDate": null,
                    "licenseStateProvCd": null,
                    "licensePermitNumber": null
                }]
            }
        }, {
            ......(lots more fields like this)
            },
            "driver": null
        }],
        "vehicles": [{
            .....(lots of single fields here)
            "coverages": {
                .....(lots of single fields here)
            }
        }],
        "customer": {
            "extensionFields": {
                "nif": "XXX"
            },
            "individualDetails": {
                ......(lots more fields like this)
            },
            "phones": [{
                "phoneNumber": "1234567890"
            }],
            "addresses": [{
                ......(lots more fields like this)
            }]
        },
        "previous_policy": null
    }
}

这里是Avro模式,对不起,它太长了

代码语言:javascript
复制
{
    "type": "record",
    "namespace": "my.namespace",
    "name": "MyEvent",
    "fields": [
                    ....lots of fields here
                    {
                        "name": "insuredsAndDrivers",
                        "default": [],
                        "type": {
                            "type": "array",
                            "items": {
                                "name": "InsuredsAndDrivers_Record",
                                "default": "",
                                "type": "record",
                                "fields": [
                                     ......(lots more fields here),
                                    {
                                        "name": "driver",
                                        "type": {
                                            "name": "Driver",
                                            "default": "",
                                            "type": "record",
                                            "fields": [{
                                                    "name": "relationshipToInsuredCd",
                                                    "type": ["string", "null"],
                                                    "default": ""
                                                },
                                                {
                                                    "name": "driverTypeCd",
                                                    "type": ["string", "null"],
                                                    "default": ""
                                                },
                                                {
                                                    "name": "occupationCd",
                                                    "type": ["string", "null"],
                                                    "default": ""
                                                },
                                                {
                                                    "name": "driverLicenses",
                                                    "default": [],
                                                    "type": {
                                                        "type": "array",
                                                        "items": {
                                                            "name": "DiverLicenses_Record",
                                                            "default": "",
                                                            "type": "record",
                                                            "fields": [{
                                                                    "name": "licenseTypeCd",
                                                                    "type": ["string", "null"],
                                                                    "default": ""
                                                                },
                                                                {
                                                                    "name": "licenseDate",
                                                                    "type": ["string", "null"],
                                                                    "default": ""
                                                                },
                                                                {
                                                                    "name": "licenseStateProvCd",
                                                                    "type": ["string", "null"],
                                                                    "default": ""
                                                                },
                                                                {
                                                                    "name": "licensePermitNumber",
                                                                    "type": ["string", "null"],
                                                                    "default": ""
                                                                }
                                                            ]
                                                        }
                                                    }
                                                }
                                            ]
                                        }
                                    }
                                ]
                            }
                        }
                    }

               ...rest of schema not relevant

我收到错误Caused by: java.lang.NullPointerException: null of com.lm.gde.eventing.avro.Driver of com.lm.gde.eventing.avro.InsuredsAndDrivers_Record of array of com.lm.gde.eventing.avro.Policy of com.lm.gde.eventing.avro.EnrichedPolicyEvent

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-15 12:47:03

数组“insuredsAndDrivers”的第二个"InsuredsAndDrivers_Record“元素:

代码语言:javascript
复制
{
   "firstName": "XXX",
   "middleName": "Driver secondLastName",
   ...... (lots more fields here)
   "phones": [],
   "emails": [],
   "insured": {
       "primaryInsuredInd": "false"
   },
   "driver": null  <---- THIS
}

driver字段为空,但架构将其定义为:

代码语言:javascript
复制
"name": "insuredsAndDrivers",
"default": [],
"type": {
    "type": "array",
    "items": { ... }
}

它不能为空。您需要提供驱动程序或使数组的项类型成为null的联合类型。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59739193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档