Search in sources :

Example 1 with FromJson

use of com.squareup.moshi.FromJson in project ProxerLibJava by proxer.

the class NotificationAdapter method fromJson.

@FromJson
Notification fromJson(final IntermediateNotification json) {
    final String base = ProxerUrls.webBase().toString();
    final HttpUrl properContentLink = HttpUrl.parse(base.substring(0, base.length() - 1) + json.contentLink);
    if (properContentLink == null) {
        throw new JsonDataException("Invalid link: " + json.contentLink);
    }
    return new Notification(json.id, json.type, json.contentId, properContentLink, json.text, json.date, json.additionalDescription);
}
Also used : JsonDataException(com.squareup.moshi.JsonDataException) HttpUrl(okhttp3.HttpUrl) Notification(me.proxer.library.entity.notifications.Notification) FromJson(com.squareup.moshi.FromJson)

Aggregations

FromJson (com.squareup.moshi.FromJson)1 JsonDataException (com.squareup.moshi.JsonDataException)1 Notification (me.proxer.library.entity.notifications.Notification)1 HttpUrl (okhttp3.HttpUrl)1