Interface EventDataMarshaller

All Known Implementing Classes:
JacksonEventDataMarshaller

public interface EventDataMarshaller
Interface implemented for transforming Java event objects and additional meta-data to JSON-like maps, and vice versa. Used for transformations to or from Event.data() and to EventCandidate.data().

To ensure interoperability, implementations of this should conform to the same JSON schema for the data event content, i.e. using metadata for EventData.metaData() and payload for EventData.payload(), e.g. as follows:

     {
         "data": {
             "metadata": {
                 "userId": "345897345"
             },
             "payload": {
                 // serialized java object
             }
         },
         // other cloud event attributes omitted for brevity
     }
 
  • Method Details

    • serialize

      <E> Map<String,?> serialize(EventData<E> data)
      Converts the given EventData to a Map representation.
      Type Parameters:
      E - the generic payload type
      Parameters:
      data - the event data
      Returns:
      a JSON-like map representation
    • deserialize

      <E> EventData<E> deserialize(Map<String,?> json, Class<E> clazz)
      Converts a JSON-like Map representation to EventData using the given Class to determine the payload type.
      Type Parameters:
      E - the generic payload type
      Parameters:
      json - the JSON-like map representation
      clazz - the target type of the EventData.payload()
      Returns:
      the event and meta-data