title: Spring Cloud @SqsListener MessageConversionException: Cannot convert from [java.lang.String] for GenericMessage
body: <p>I'm seeing the following exception when I try to consume an SQS message: </p>
  
  <pre><code>org.springframework.messaging.converter.MessageConversionException: 
  
  Cannot convert from [java.lang.String] to [com.example.demo.Foo] for GenericMessage [payload={}, headers={LogicalResourceId=my-queue, ApproximateReceiveCount=1, SentTimestamp=1529021258825, ReceiptHandle=xxxx, Visibility=org.springframework.cloud.aws.messaging.listener.QueueMessageVisibility@47ce6922, SenderId=xxxx, lookupDestination=my-queue, ApproximateFirstReceiveTimestamp=1529021264456, MessageId=xxxx}]
      at org.springframework.messaging.handler.annotation.support.PayloadArgumentResolver.resolveArgument(PayloadArgumentResolver.java:144)
      at org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:116)
      at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:137)
      at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:109)
      at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:515)
      at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:473)
      at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:409)
      at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.executeMessage(SimpleMessageListenerContainer.java:205)
      at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:342)
      at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:397)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>Spring Boot code is as follows:</p>
  
  <pre><code>@Configuration
  @EnableSqs
  public class AmazonSqsConfiguration {
  
      @Bean
      public AmazonSQS amazonSQSAsync() {
          return AmazonSQSAsyncClientBuilder.standard()
              .withRegion(Regions.US_WEST_2)
              .build();
      }
  }
  
  @Service
  public class MyService {
  
      // Throws MessageConversionException
      @SqsListener("my-queue")
      public void listen(Foo payload) {
  
      }
  
      // Works fine
      @SqsListener("my-queue")
      public void listen(String payload) {
  
      }
  }
  </code></pre>
  
  <p>I'm using <code>org.springframework.cloud:spring-cloud-aws-messaging:2.0.0.RC2</code></p>
  
  <p>I do have Jackson 2 libraries on my classpath, so <code>PayloadArgumentResolver</code> is trying to use <code>MappingJackson2MessageConverter</code> to deserialize my message payload.  However, because the SQS message is missing a <code>contentType</code> header and <code>strictContentTypeMatch</code> is set to true, <code>canConvertFrom</code> returns false.</p>
  
  <p><a href="https://github.com/spring-projects/spring-framework/blob/f5e8f4983f7653169f3da8a3287499fce93cadd4/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java#L237" rel="noreferrer">https://github.com/spring-projects/spring-framework/blob/f5e8f4983f7653169f3da8a3287499fce93cadd4/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractMessageConverter.java#L237</a></p>
  
  <p>I don't see how it is possible to set <code>contentType</code> header for SQS messages - am I missing something?</p>
  
  <p>Should Spring Cloud <code>QueueMessageHandler</code> be setting <code>strictContentTypeMatch</code> to true?</p>
  
  <p><a href="https://github.com/spring-cloud/spring-cloud-aws/blob/6a7c3c31709d4239131b27936de29385df414d41/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandler.java#L217" rel="noreferrer">https://github.com/spring-cloud/spring-cloud-aws/blob/6a7c3c31709d4239131b27936de29385df414d41/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/listener/QueueMessageHandler.java#L217</a></p>