Package kong.unirest.core.java
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/
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TasObject(Class<? extends T> responseClass)Deserialize the data of the event using the Unirest Config's ObjectMapper<T> TasObject(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>Stringdata()The data field for the message.booleanequals(Object o)Stringevent()A string identifying the type of event described.inthashCode()Stringid()The event ID to set the EventSource object's last event ID value.StringtoString()
-
-
-
Constructor Detail
-
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 IDevent- the event label. "message" is the default from the serverdata- 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
-
-
Method Detail
-
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
-
-