Class JacksonPubSubMessageConverter

java.lang.Object
com.google.cloud.spring.pubsub.support.converter.JacksonPubSubMessageConverter
All Implemented Interfaces:
PubSubMessageConverter

public class JacksonPubSubMessageConverter extends Object implements PubSubMessageConverter
A converter using Jackson JSON.
  • Constructor Details

    • JacksonPubSubMessageConverter

      public JacksonPubSubMessageConverter(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
      Constructor.
      Parameters:
      objectMapper - the object mapper used to create and read JSON.
  • Method Details

    • toPubSubMessage

      public com.google.pubsub.v1.PubsubMessage toPubSubMessage(Object payload, Map<String,String> headers)
      Description copied from interface: PubSubMessageConverter
      Create a PubsubMessage given an object for the payload and a map of headers.
      Specified by:
      toPubSubMessage in interface PubSubMessageConverter
      Parameters:
      payload - the object to place into the message payload
      headers - the headers of the message
      Returns:
      the PubsubMessage ready to be sent
    • fromPubSubMessage

      public <T> T fromPubSubMessage(com.google.pubsub.v1.PubsubMessage message, Class<T> payloadType)
      Description copied from interface: PubSubMessageConverter
      Convert the payload of a given PubsubMessage to a desired Java type.
      Specified by:
      fromPubSubMessage in interface PubSubMessageConverter
      Type Parameters:
      T - the type of the payload
      Parameters:
      message - the message containing the payload of the object
      payloadType - the desired type of the object
      Returns:
      the object converted from the message's payload