Class JsonFormat

java.lang.Object
io.cloudevents.jackson.JsonFormat
All Implemented Interfaces:
io.cloudevents.core.format.EventFormat

public final class JsonFormat extends Object implements io.cloudevents.core.format.EventFormat
Implementation of EventFormat for JSON event format using Jackson. This format is resolvable with EventFormatProvider using the content type CONTENT_TYPE.

If you want to use the CloudEvent serializers/deserializers directly in your mapper, you can use getCloudEventJacksonModule() or getCloudEventJacksonModule(boolean, boolean) to get a SimpleModule to register in your ObjectMapper instance.

  • Field Details

    • CONTENT_TYPE

      public static final String CONTENT_TYPE
      Content type associated with the JSON event format
      See Also:
  • Constructor Details

    • JsonFormat

      public JsonFormat(boolean forceDataBase64Serialization, boolean forceStringSerialization)
      Create a new instance of this class customizing the serialization configuration.
      Parameters:
      forceDataBase64Serialization - force json base64 encoding for data
      forceStringSerialization - force string serialization for non json data field
      See Also:
    • JsonFormat

      public JsonFormat(JsonFormatOptions options)
      Create a new instance of this class customizing the serialization configuration.
      Parameters:
      options - json serialization / deserialization options
    • JsonFormat

      public JsonFormat()
      Create a new instance of this class with default serialization configuration
  • Method Details

    • withForceJsonDataToBase64

      public JsonFormat withForceJsonDataToBase64()
      Returns:
      a copy of this JsonFormat that serialize events with json data with Base64 encoding
    • withForceNonJsonDataToString

      public JsonFormat withForceNonJsonDataToString()
      Returns:
      a copy of this JsonFormat that serialize events with non-json data as string
    • withForceExtensionNameLowerCaseDeserialization

      public JsonFormat withForceExtensionNameLowerCaseDeserialization()
      Returns:
      a copy of this JsonFormat that deserialize events with converting extension name lower case.
    • withForceIgnoreInvalidExtensionNameDeserialization

      public JsonFormat withForceIgnoreInvalidExtensionNameDeserialization()
      Returns:
      a copy of this JsonFormat that deserialize events with ignoring invalid extension name
    • serialize

      public byte[] serialize(io.cloudevents.CloudEvent event) throws io.cloudevents.core.format.EventSerializationException
      Specified by:
      serialize in interface io.cloudevents.core.format.EventFormat
      Throws:
      io.cloudevents.core.format.EventSerializationException
    • deserialize

      public io.cloudevents.CloudEvent deserialize(byte[] bytes) throws io.cloudevents.core.format.EventDeserializationException
      Specified by:
      deserialize in interface io.cloudevents.core.format.EventFormat
      Throws:
      io.cloudevents.core.format.EventDeserializationException
    • deserialize

      public io.cloudevents.CloudEvent deserialize(byte[] bytes, io.cloudevents.rw.CloudEventDataMapper<? extends io.cloudevents.CloudEventData> mapper) throws io.cloudevents.core.format.EventDeserializationException
      Specified by:
      deserialize in interface io.cloudevents.core.format.EventFormat
      Throws:
      io.cloudevents.core.format.EventDeserializationException
    • serializedContentType

      public String serializedContentType()
      Specified by:
      serializedContentType in interface io.cloudevents.core.format.EventFormat
    • getCloudEventJacksonModule

      public static SimpleModule getCloudEventJacksonModule()
      Returns:
      a SimpleModule with CloudEvent serializer/deserializer configured using default values.
    • getCloudEventJacksonModule

      public static SimpleModule getCloudEventJacksonModule(boolean forceDataBase64Serialization, boolean forceStringSerialization)
      Parameters:
      forceDataBase64Serialization - force json base64 encoding for data
      forceStringSerialization - force string serialization for non json data field
      Returns:
      a JacksonModule with CloudEvent serializer/deserializer customizing the data serialization.
      See Also:
    • getCloudEventJacksonModule

      public static SimpleModule getCloudEventJacksonModule(JsonFormatOptions options)
      Parameters:
      options - json serialization / deserialization options
      Returns:
      a JacksonModule with CloudEvent serializer/deserializer customizing the data serialization.