Class Event

java.lang.Object
kong.unirest.core.java.Event

public class Event extends Object
A server sent event. Generally modeled on the HTML5 EventSource standard https://html.spec.whatwg.org/multipage/
  • Constructor Summary

    Constructors
    Constructor
    Description
    Event(String id, String event, String data)
     
    Event(String id, String event, String data, Config config)
    Constructor used by unirest which includes the Unirest config which uis used for event serialization
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    asObject(Class<? extends T> responseClass)
    Deserialize the data of the event using the Unirest Config's ObjectMapper
    <T> T
    asObject(GenericType<T> genericType)
    Deserialize the data of the event using the Unirest Config's ObjectMapper This method takes a GenericType which retains Generics information for types lke List<Foo>
    The data field for the message.
    boolean
     
    A string identifying the type of event described.
    int
     
    id()
    The event ID to set the EventSource object's last event ID value.
     

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Event

      public Event(String id, String event, String data, Config config)
      Constructor used by unirest which includes the Unirest config which uis used for event serialization
      Parameters:
      id - The event ID
      event - the event label. "message" is the default from the server
      data - the data in the event. This is concatenated from all lines before a dispatch event (a blank line)
      config - the unirest config used for deserialization
    • Event

      public Event(String id, String event, String data)
  • Method Details

    • data

      public String data()
      The data field for the message. When the EventSource receives multiple consecutive lines that begin with data:, it concatenates them, inserting a newline character between each one. Trailing newlines are removed.
      Returns:
      the data
    • id

      public String id()
      The event ID to set the EventSource object's last event ID value.
      Returns:
      the id
    • event

      public String event()
      A string identifying the type of event described. If this is specified, an event will be dispatched on the browser to the listener for the specified event name;
      Returns:
      the event name
    • asObject

      public <T> T asObject(Class<? extends T> responseClass)
      Deserialize the data of the event using the Unirest Config's ObjectMapper
      Type Parameters:
      T - the class type
      Parameters:
      responseClass - the type of class you want back
      Returns:
      an instance of the class
    • asObject

      public <T> T asObject(GenericType<T> genericType)
      Deserialize the data of the event using the Unirest Config's ObjectMapper This method takes a GenericType which retains Generics information for types lke List<Foo>
      Type Parameters:
      T - the class type
      Parameters:
      genericType - the type of class you want back using a generictype object
      Returns:
      an instance of the class
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object