无法从 START_ARRAY 令牌中反序列化 `com.dckr.microsvc.model.Event` 的实例
Cannot deserialize instance of `com.dckr.microsvc.model.Event` out of START_ARRAY token
我从 kafka 生产者那里得到 json 有效负载。
[
{
"mcID": "840465",
"subscriberId": "",
"sequenceNumber": "",
"membershipSourceSystem": "",
"groupNumber": "",
"userNm": "174988",
"webGuid": "",
"interactionSource": "Engage",
"channel": "Mobile",
"sessionId": "",
"deviceId": "",
"direction": "",
"injectionTimestamp": "2020-09-25T00:00:00.000-04:00",
"associateId": "",
"contactType": "",
"contactEmail": "",
"contactFirstName": "SUS",
"contactMiddletName": "",
"contactLastName": "HAT",
"contactDOB": "19540807",
"outcome": "",
"notes": "",
"interactionIntent": {
"interactionIntent": {
"registration": {
"eventTimestamp": "2020-09-25T00:00:00.000-04:00"
}
},
"login": [
{
"totalVisits": "1",
"totalCareTeamProviders": "2",
"totalTrackersPurchased": "0",
"eventTimestamp": "2020-09-25T00:00:00.000-04:00"
}
]
}
}
]
我在 kafka 侦听器端遇到以下问题。
2020-12-03 23:45:30.698 [org.springframework.kafka.KafkaListenerEndpointContainer#0-8-C-1] ERROR c.a.e.d.m.e.k.consumer.EventListener -
EEECATLIGHTDIGITALINTERACTIONS KAFKA CONSUMER: error caught in kafka listener: Cannot deserialize instance of `com.anthem.emep.dckr.microsvc.eeecatlightdigitalinteractions.model.Event` out of START_ARRAY token
at [Source: (String)"[{"mcID":"840465","subscriberId":"","sequenceNumber":"","membershipSourceSystem":"","groupNumber":"","userNm":"174988","webGuid":"","interactionSource":"Engage","channel":"Mobile","sessionId":"","deviceId":"","direction":"","injectionTimestamp":"2020-09-25T00:00:00.000-04:00","associateId":"","contactType":"","contactEmail":"","contactFirstName":"SUSAN","contactMiddletName":"","contactLastName":"HATCHER","contactDOB":"19540807","outcome":"","notes":"","interacti"[truncated 238 chars]; line: 1, column: 1]
2020-12-03 23:45:30.803 [org.springframework.kafka.KafkaListenerEndpointContainer#0-10-C-1] ERROR c.a.e.d.m.e.k.consumer.EventListener - error caught in kafka listener: Cannot deserialize instance of `com.anthem.emep.dckr.microsvc.eeecatlightdigitalinteractions.model.Event` out of START_ARRAY token
我们什么时候得到这种异常?是因为对象没有正确映射吗?有人可以帮忙吗?
Kafka 消费者代码:
@KafkaListener(topics ="#{'${applicationProperties.kafkapropmap.kafka.topics}'.split('\\ ')}")
public HttpStatus receiveMessages(ConsumerRecord<?,?> consumerRecord, Acknowledgment acknowledgment) {
try {
log.info("event Received = "+ (String) consumerRecord.value());
ObjectMapper mapper = new ObjectMapper();
Event event = mapper.readValue(((String) consumerRecord.value()), Event.class);
} catch(Exception ex) {
log.error("{} error caught in kafka listener: {}", ApplicationConstant.MEMBER_MSG_HEADER, ex.getMessage());
acknowledgment.acknowledge();
}
}
Kafka 正在向您发送一个包含在 [] 中的负载。这意味着你必须将它映射到列表。
试试这个:
ObjectMapper mapper = new ObjectMapper();
List<Event> events = mapper.readValue(((String) consumerRecord.value()),
new TypeReference<List<Event>>() {
});
我从 kafka 生产者那里得到 json 有效负载。
[
{
"mcID": "840465",
"subscriberId": "",
"sequenceNumber": "",
"membershipSourceSystem": "",
"groupNumber": "",
"userNm": "174988",
"webGuid": "",
"interactionSource": "Engage",
"channel": "Mobile",
"sessionId": "",
"deviceId": "",
"direction": "",
"injectionTimestamp": "2020-09-25T00:00:00.000-04:00",
"associateId": "",
"contactType": "",
"contactEmail": "",
"contactFirstName": "SUS",
"contactMiddletName": "",
"contactLastName": "HAT",
"contactDOB": "19540807",
"outcome": "",
"notes": "",
"interactionIntent": {
"interactionIntent": {
"registration": {
"eventTimestamp": "2020-09-25T00:00:00.000-04:00"
}
},
"login": [
{
"totalVisits": "1",
"totalCareTeamProviders": "2",
"totalTrackersPurchased": "0",
"eventTimestamp": "2020-09-25T00:00:00.000-04:00"
}
]
}
}
]
我在 kafka 侦听器端遇到以下问题。
2020-12-03 23:45:30.698 [org.springframework.kafka.KafkaListenerEndpointContainer#0-8-C-1] ERROR c.a.e.d.m.e.k.consumer.EventListener -
EEECATLIGHTDIGITALINTERACTIONS KAFKA CONSUMER: error caught in kafka listener: Cannot deserialize instance of `com.anthem.emep.dckr.microsvc.eeecatlightdigitalinteractions.model.Event` out of START_ARRAY token
at [Source: (String)"[{"mcID":"840465","subscriberId":"","sequenceNumber":"","membershipSourceSystem":"","groupNumber":"","userNm":"174988","webGuid":"","interactionSource":"Engage","channel":"Mobile","sessionId":"","deviceId":"","direction":"","injectionTimestamp":"2020-09-25T00:00:00.000-04:00","associateId":"","contactType":"","contactEmail":"","contactFirstName":"SUSAN","contactMiddletName":"","contactLastName":"HATCHER","contactDOB":"19540807","outcome":"","notes":"","interacti"[truncated 238 chars]; line: 1, column: 1]
2020-12-03 23:45:30.803 [org.springframework.kafka.KafkaListenerEndpointContainer#0-10-C-1] ERROR c.a.e.d.m.e.k.consumer.EventListener - error caught in kafka listener: Cannot deserialize instance of `com.anthem.emep.dckr.microsvc.eeecatlightdigitalinteractions.model.Event` out of START_ARRAY token
我们什么时候得到这种异常?是因为对象没有正确映射吗?有人可以帮忙吗?
Kafka 消费者代码:
@KafkaListener(topics ="#{'${applicationProperties.kafkapropmap.kafka.topics}'.split('\\ ')}")
public HttpStatus receiveMessages(ConsumerRecord<?,?> consumerRecord, Acknowledgment acknowledgment) {
try {
log.info("event Received = "+ (String) consumerRecord.value());
ObjectMapper mapper = new ObjectMapper();
Event event = mapper.readValue(((String) consumerRecord.value()), Event.class);
} catch(Exception ex) {
log.error("{} error caught in kafka listener: {}", ApplicationConstant.MEMBER_MSG_HEADER, ex.getMessage());
acknowledgment.acknowledge();
}
}
Kafka 正在向您发送一个包含在 [] 中的负载。这意味着你必须将它映射到列表。
试试这个:
ObjectMapper mapper = new ObjectMapper();
List<Event> events = mapper.readValue(((String) consumerRecord.value()),
new TypeReference<List<Event>>() {
});