title: Spring Cloud stream with RabbitMQ sending any Date Like LocalDateTime or Instant
body: <p>I have an issue with consuming messages from a Rabbit queue whenever there is an object with any Date like LocalDateTime, Instant,....
  Here is my setup:</p>
  <p>Spring Boot Application</p>
  <pre><code>@SpringBootApplication
  public class SpringCloudStreamProcessorApplication {
      public static void main(String[] args) {
          SpringApplication.run(SpringCloudStreamProcessorApplication.class, args);
      }
  }
  </code></pre>
  <p>My consumer setup:</p>
  <pre><code>@Component
  public class ValueConsumer {
  
      @Bean
      public Consumer&lt;StationExt&gt; createStation() {
          return (value) -&gt; {
              log.info(&quot;Received station {}&quot;, value);
          };
      }
  }
  </code></pre>
  <p>My entity representation</p>
  <pre><code>@Data
  @Builder
  @NoArgsConstructor
  @AllArgsConstructor
  public class StationExt {
      private String id;
      private String name;
      private LocalDate createdAt;
  }
  </code></pre>
  <p>My application.yml</p>
  <pre><code>spring:
    cloud:
      function:
        definition: createStation
      stream:
        bindings:
          createStation-in-0:
            destination: created_station
            durableSubscription: true
            group: consumer
  </code></pre>
  <p>My pom.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.7.2&lt;/version&gt;
          &lt;relativePath/&gt;
      &lt;/parent&gt;
  
  
      &lt;groupId&gt;com.consumer&lt;/groupId&gt;
      &lt;artifactId&gt;consumer-prototype&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;Consumer Prototype&lt;/name&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-amqp&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-stream&lt;/artifactId&gt;
              &lt;version&gt;3.2.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.cloud&lt;/groupId&gt;
              &lt;artifactId&gt;spring-cloud-stream-binder-rabbit&lt;/artifactId&gt;
              &lt;version&gt;3.1.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
  
  
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>When I publish this json message on the queue via rabbitMQ management console:</p>
  <pre><code>{
      &quot;id&quot;: &quot;ef19bf9b-99c0-4f1e-ab84-d5819a87002e&quot;,
      &quot;name&quot;: &quot;My Station Two&quot;,
      &quot;createdAt&quot;: null
  }
  </code></pre>
  <p>I receive the object StationExt in the Consumer:</p>
  <pre><code>2022-08-23 19:24:36.759  INFO 382668 --- [ion.processor-1] c.consumer.prototyp.ValueConsumer: Received stationStationExt(id=ef19bf9b-99c0-4f1e-ab84-d5819a87002e, name=My Station Two, createdAt=null)
  </code></pre>
  <p>whenever I use any value for the date</p>
  <pre><code>{
      &quot;id&quot;: &quot;ef19bf9b-99c0-4f1e-ab84-d5819a87002e&quot;,
      &quot;name&quot;: &quot;My Station Two&quot;,
      &quot;createdAt&quot;: &quot;2022-08-23&quot;
  }
  </code></pre>
  <p>this exception is thrown:</p>
  <pre><code>2022-08-23 19:26:18.965 ERROR 382668 --- [ion.processor-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessageHandlingException: error occurred in message handler [org.springframework.cloud.stream.function.FunctionConfiguration$FunctionToDestinationBinder$1@53ca55e1]; nested exception is java.lang.ClassCastException: class [B cannot be cast to class com.consumer.prototyp.StationExt ([B is in module java.base of loader 'bootstrap'; com.consumer.prototyp.processor.StationExt is in unnamed module of loader 'app'), failedMessage=GenericMessage [payload=byte[115], headers={amqp_receivedDeliveryMode=NON_PERSISTENT, amqp_receivedRoutingKey=created_station.processor, amqp_receivedExchange=, amqp_deliveryTag=8, deliveryAttempt=3, amqp_consumerQueue=created_station.processor, amqp_redelivered=false, id=76dd27c6-e3ea-06ff-b7d3-4dac62560611, amqp_consumerTag=amq.ctag-2eI4LcNYBLQONuGLGThIpg, sourceData=(Body:'[B@610afce2(byte[115])' MessageProperties [headers={}, contentLength=0, receivedDeliveryMode=NON_PERSISTENT, redelivered=false, receivedExchange=, receivedRoutingKey=created_station.processor, deliveryTag=8, consumerTag=amq.ctag-2eI4LcNYBLQONuGLGThIpg, consumerQueue=created_station.processor]), contentType=application/json, timestamp=1661275575944}]
      at org.springframework.integration.support.utils.IntegrationUtils.wrapInHandlingExceptionIfNecessary(IntegrationUtils.java:191)
      at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:65)
      at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115)
      at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133)
      at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106)
      at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72)
      at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:317)
      at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:272)
      at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187)
      at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166)
      at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
      at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109)
      at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:216)
      at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter.access$1300(AmqpInboundChannelAdapter.java:69)
      at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter$Listener.lambda$onMessage$0(AmqpInboundChannelAdapter.java:374)
      at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329)
      at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:225)
      at org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter$Listener.onMessage(AmqpInboundChannelAdapter.java:370)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1670)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1589)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1577)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1568)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1512)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:993)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:940)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:84)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1317)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1223)
      at java.base/java.lang.Thread.run(Thread.java:829)
  Caused by: java.lang.ClassCastException: class [B cannot be cast to class com.consumer.prototyp.StationExt ([B is in module java.base of loader 'bootstrap'; com.consumer.prototyp.StationExt is in unnamed module of loader 'app')
      at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.invokeConsumer(SimpleFunctionRegistry.java:784)
      at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.doApply(SimpleFunctionRegistry.java:589)
      at org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper.apply(SimpleFunctionRegistry.java:435)
      at org.springframework.cloud.stream.function.PartitionAwareFunctionWrapper.apply(PartitionAwareFunctionWrapper.java:79)
      at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionWrapper.apply(FunctionConfiguration.java:717)
      at org.springframework.cloud.stream.function.FunctionConfiguration$FunctionToDestinationBinder$1.handleMessageInternal(FunctionConfiguration.java:559)
      at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:56)
      ... 27 more
  </code></pre>
  <p>I have tried with Instant, OffsetDateTime, LocalDatetime but the error is always the same.
  I tried annotating the LocalDate with JsonFormat like this:</p>
  <pre><code>@JsonFormat(pattern = &quot;dd-MM-yyyy&quot;, shape = JsonFormat.Shape.ANY)
      private LocalDate createdAt;
  </code></pre>
  <p>But the error always remains the same.</p>
  <p>Tried with different versions in the pom for spring-cloud-stream and spring-cloud-stream-binder-rabbit.</p>
  <p>Does anyone have any idea why this isn't working?</p>