当前位置:网站首页>com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
2022-06-27 00:06:00 【tag心動】
錯誤場景:
rabbitmq消費端接收消息,提示無法序列化。 根據以下報錯得知, 是java.time.LocalDateTime類型的原因. ObjectMapper 不能對LocalDateTime 序列化
問題描述
rabbitmq消費端接收消息,錯誤信息:
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string.
at [Source: (String)"xx這裏是接收json對象xx"[truncated 357 chars]; line: 1, column: 606] (through reference chain: com.csair.tang.logs.receiver.LogFlightcenterMessage["operationTime"])
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1468)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1242)
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1170)
at com.fasterxml.jackson.datatype.jsr310.deser.JSR310DeserializerBase._handleUnexpectedToken(JSR310DeserializerBase.java:148)
at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:159)
at com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer.deserialize(LocalDateTimeDeserializer.java:39)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:371)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:164)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4526)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3468)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3436)
at com.csair.tang.logs.receiver.LogFlightcenterReceiver.onTestMessage(LogFlightcenterReceiver.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:171)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120)
at org.springframework.amqp.rabbit.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:53)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:239)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.invokeHandlerAndProcessResult(MessagingMessageListenerAdapter.java:191)
at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:137)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1630)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1549)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1537)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1528)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1472)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:977)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:923)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:83)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1298)
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1204)
at java.lang.Thread.run(Thread.java:748)
2022-06-23 23:34:13.056 ERROR[org.springframework.amqp.rabbit.RabbitListenerEndpointContainer#0-1]com.csair.tang.logs.receiver.LogFlightcenterReceiver.onTestMessage:53 -日志接收异常:Expected array or string.
解决方案
在生產者消息模板屬性加上以下注解:
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)

再重啟消費者服務,重新發送消息測試
边栏推荐
- Implement the queue through two stacks
- Simple test lightweight expression calculator fly
- PHP代码审计系列(一) 基础:方法、思路、流程
- Target tracking shooting? Target occlusion shooting? With 1.9 billion installed petal apps, what unique features attract users?
- 颜色搭配和相关问题
- 1+1<2 ?! Interpretation of hesic papers
- 入侵痕迹清理
- 固有色和环境色
- [microservices] Understanding microservices
- Encapsulate servlet unified processing request
猜你喜欢

我的c语言进阶学习笔记 ----- 关键字

Lorsque le transformateur rencontre l'équation différentielle partielle

当Transformer遇见偏微分方程求解

利用burp精准定位攻击者

Typera set title auto numbering

The user adds a timer function in the handler () goroutine. If it times out, it will be kicked out

Amway! How to provide high-quality issue? That's what Xueba wrote!

万字详解-MindArmour 小白教程!

不会写免杀也能轻松过defender上线CS

On cap theorem in distributed system development technology
随机推荐
Is the low commission free account opening channel safe?
The fourth bullet of redis interview eight part essay (end)
Super hard core! Can the family photo album on Huawei's smart screen be classified automatically and accurately?
Technical dry goods | what is a big model? Oversized model? Foundation Model?
Would you like to buy stocks? Where do you open an account in a securities company? The Commission is lower and safer
【leetcode】275. H index II
Is it reliable to open an account on a stock trading mobile phone? Is it safe to open an account online and speculate in stocks
xshell的安装、xftp的安装
Unity初学者肯定能用得上的50个小技巧
手机炒股靠谱吗 网上开户炒股安全吗
有哪些劵商推荐?现在在线开户安全么?
超硬核!华为智慧屏上的家庭相册竟可以自动精准分类?
Implement the queue through two stacks
如何通俗易懂的描述机器学习的流程?
“message“:“Bad capabilities. Specify either app or appTopLevelWindow to create a session“
[微服务]Eureka
利用burp精准定位攻击者
In the Internet industry, there are many certificates with high gold content. How many do you have?
ASP.Net Core创建MVC项目上传文件(缓冲方式)
Service discovery, storage engine and static website of go language