Class GsonNotificationReader

java.lang.Object
com.reallifedeveloper.common.infrastructure.GsonNotificationReader
All Implemented Interfaces:
NotificationReader

public final class GsonNotificationReader extends Object implements NotificationReader
An implementation of the NotificationReader interface that works with JSON as the serialized form, using Gson to parse the JSON string.
Author:
RealLifeDeveloper
  • Constructor Details

    • GsonNotificationReader

      public GsonNotificationReader(String jsonNotification)
      Creates a new GsonNotificationReader that parses the given JSON-serialized notification.
      Parameters:
      jsonNotification - the JSON representation of the notification to read
      Throws:
      IllegalArgumentException - if jsonNotification is null or not a valid JSON object
  • Method Details

    • eventType

      public String eventType()
      Description copied from interface: NotificationReader
      Gives the name of the domain event class.
      Specified by:
      eventType in interface NotificationReader
      Returns:
      the name of the domain event class
    • storedEventId

      public Long storedEventId()
      Description copied from interface: NotificationReader
      Gives the ID of the StoredEvent that the Notification is based on.
      Specified by:
      storedEventId in interface NotificationReader
      Returns:
      the ID of the StoredEvent
    • occurredOn

      public ZonedDateTime occurredOn()
      Description copied from interface: NotificationReader
      Gives the date and time when the domain event occurred.
      Specified by:
      occurredOn in interface NotificationReader
      Returns:
      the date and time the domain event occurred
    • eventVersion

      public Integer eventVersion()
      Description copied from interface: NotificationReader
      Gives the version of the domain event.
      Specified by:
      eventVersion in interface NotificationReader
      Returns:
      the version of the domain event
    • eventIntValue

      public Optional<Integer> eventIntValue(String fieldName)
      Description copied from interface: NotificationReader
      Gives the integer value of a field in the domain event.
      Specified by:
      eventIntValue in interface NotificationReader
      Parameters:
      fieldName - the name of the field to lookup, potentially nested, e.g., "foo.bar"
      Returns:
      the optoinl integer value of the field
    • eventLongValue

      public Optional<Long> eventLongValue(String fieldName)
      Description copied from interface: NotificationReader
      Gives the long integer value of a field in the domain event.
      Specified by:
      eventLongValue in interface NotificationReader
      Parameters:
      fieldName - the name of the field to lookup, potentially nested, e.g., "foo.bar"
      Returns:
      the optional long integer value of the field
    • eventDoubleValue

      public Optional<Double> eventDoubleValue(String fieldName)
      Description copied from interface: NotificationReader
      Gives the double value of a field in the domain event.
      Specified by:
      eventDoubleValue in interface NotificationReader
      Parameters:
      fieldName - the name of the field to lookup, potentially nested, e.g., "foo.bar"
      Returns:
      the optional double value of the field
    • eventStringValue

      public Optional<String> eventStringValue(String fieldName)
      Description copied from interface: NotificationReader
      Gives the string value of a field in the domain event.
      Specified by:
      eventStringValue in interface NotificationReader
      Parameters:
      fieldName - the name of the field to lookup, potentially nested, e.g., "foo.bar"
      Returns:
      the optional string value of the field
    • zonedDateTimeValue

      public Optional<ZonedDateTime> zonedDateTimeValue(String fieldName)
      Description copied from interface: NotificationReader
      Gives the value of a field in the domain event as a java.time.ZonedDateTime object.
      Specified by:
      zonedDateTimeValue in interface NotificationReader
      Parameters:
      fieldName - the name of the field to lookup, potentially nested, e.g., "foo.bar"
      Returns:
      the optional java.time.ZonedDateTime value of the field