T
- Type of the data contained within a notificationpublic abstract class JsonNotificationCallback<T> extends TypedNotificationCallback<T>
TypedNotificationCallback
which uses an JSON content encoding.
Must not be implemented in form of an anonymous class as this will break serialization.
Implementation should be thread-safe.
State will only be persisted once when a subscription is created. All state changes occurring
during the .handleNotification(..)
call will be lost.
class MyJsonNotificationCallback extends JsonNotificationCallback<ItemList> { void handleNotification( Subscription subscription, TypedNotification<ItemList> notification) { for (Item item in notification.getContent().getItems()) { System.out.println(item.getId()); } } } JsonFactory createJsonFactory() { return new JacksonFactory(); } ... service.items.list("someID").subscribe(new MyJsonNotificationCallback()).execute()
Constructor and Description |
---|
JsonNotificationCallback() |
Modifier and Type | Method and Description |
---|---|
protected abstract com.google.api.client.json.JsonFactory |
createJsonFactory()
Creates a new JSON factory which is used to deserialize notifications.
|
com.google.api.client.json.JsonFactory |
getJsonFactory()
Returns the JSON-factory used by this handler.
|
protected com.google.api.client.util.ObjectParser |
getParser(UnparsedNotification notification)
Returns an
ObjectParser which can be used to parse this notification. |
JsonNotificationCallback<T> |
setDataType(Class<T> dataClass)
Sets the data type which this handler can parse or
Void.class if no data type is
expected. |
getDataClass, handleNotification, handleNotification
public final com.google.api.client.json.JsonFactory getJsonFactory() throws IOException
IOException
protected abstract com.google.api.client.json.JsonFactory createJsonFactory() throws IOException
IOException
protected final com.google.api.client.util.ObjectParser getParser(UnparsedNotification notification) throws IOException
TypedNotificationCallback
ObjectParser
which can be used to parse this notification.getParser
in class TypedNotificationCallback<T>
notification
- Notification which should be parsable by the returned parserIOException
public JsonNotificationCallback<T> setDataType(Class<T> dataClass)
TypedNotificationCallback
Void.class
if no data type is
expected.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
setDataType
in class TypedNotificationCallback<T>
Copyright © 2010-2013 Google. All Rights Reserved.