title: Spring Integration convert payload to object in service activator
body: <p>I am following this <a href="https://spring.io/guides/gs/messaging-gcp-pubsub/" rel="nofollow noreferrer">guide</a> to read email notifications from a topic in Google Pub/Sub. Once the application starts, I see messages arriving on the console like this:</p>
  
  <pre><code>Message arrived! Payload: {"emailAddress":"xxxxx@gmail.com","historyId":712315}
  </code></pre>
  
  <p>How do I convert the payload to an object so I can retrieve the emailAddress and historyId?</p>
  
  <p>The service activator looks like this:</p>
  
  <pre><code>@Bean
    @ServiceActivator(inputChannel = "pubsubInputChannel")
    public MessageHandler messageReceiver() {
      return message -&gt; {
        LOGGER.info("Message arrived! Payload: " + message.getPayload());
        AckReplyConsumer consumer =
            (AckReplyConsumer) message.getHeaders().get(GcpPubSubHeaders.ACKNOWLEDGEMENT);
        consumer.ack();
      };
    }
  </code></pre>
  
  <p>And the POJO object I want the payload converted to is:</p>
  
  <pre><code>public class MessageNotification {
  
      private String emailAddress;
  
      private BigInteger historyId;
  
      public String getEmailAddress() {
          return emailAddress;
      }
  
      public BigInteger getHistoryId() {
          return historyId;
      }
  
      public void setHistoryId(BigInteger historyId) {
          this.historyId = historyId;
      }
  
      public void setEmailAddress(String emailAddress) {
          this.emailAddress = emailAddress;
      }
  }
  </code></pre>