Android Open Source - Buddy-Android-SDK Json Envelope






From Project

Back to project page Buddy-Android-SDK.

License

The source code is released under:

Apache License

If you think the Android project Buddy-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.buddy.sdk;
/*from   w w  w .ja  va2 s  .  co  m*/

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import org.json.JSONObject;

class JsonEnvelope<T> extends JsonEnvelopeBase {
  
  public T result;

    public JsonEnvelope() {

    }

    public JsonEnvelope(JsonObject json, T result) {

        JsonElement errorElement = json.get("error");
        JsonElement errorNumberElement = json.get("errorNumber");
        JsonElement messageElement = json.get("message");
        JsonElement requestIdElement = json.get("request_id");
        JsonElement statusElement = json.get("status");

        if (errorElement != null) error = errorElement.getAsString();
        if (errorNumberElement != null) errorCode = errorNumberElement.getAsInt();
        if (messageElement != null) message = messageElement.getAsString();
        if (statusElement != null) status = statusElement.getAsInt();
        if (requestIdElement != null) request_id = requestIdElement.getAsString();


        this.result = result;
    }

    public JsonEnvelope(JSONObject json, T result) {
        error = json.optString("error");
        errorCode = json.optInt("errorNumber");
        message = json.optString("message");
        status = json.optInt("status");
        request_id = json.optString("request_id");
        this.result = result;
    }

    public <T2> JsonEnvelope<T2> convert(T2 newValue) {
        JsonEnvelope<T2> newEnvelope = new JsonEnvelope<T2>();
        newEnvelope.request_id = request_id;
        newEnvelope.status = status;
        newEnvelope.error = error;
        newEnvelope.message = message;
        newEnvelope.errorCode = errorCode;
        newEnvelope.result = newValue;
        return newEnvelope;
    }
}




Java Source Code List

chat.sample.buddy.com.buddychat.ApplicationTest.java
chat.sample.buddy.com.buddychat.BuddyChatApplication.java
chat.sample.buddy.com.buddychat.Chat.java
chat.sample.buddy.com.buddychat.GcmBroadcastReceiver.java
chat.sample.buddy.com.buddychat.GcmIntentService.java
chat.sample.buddy.com.buddychat.GetCurrentUserCallback.java
chat.sample.buddy.com.buddychat.Loading.java
chat.sample.buddy.com.buddychat.Login.java
chat.sample.buddy.com.buddychat.MainScreen.java
chat.sample.buddy.com.buddychat.Signup.java
chat.sample.buddy.com.buddychat.SimpleAdapter.java
com.buddy.sample.buddychat.LoginActivity.java
com.buddy.sdk.AccessTokenCallback.java
com.buddy.sdk.BuddyCallback.java
com.buddy.sdk.BuddyClientImpl.java
com.buddy.sdk.BuddyClientOptions.java
com.buddy.sdk.BuddyClient.java
com.buddy.sdk.BuddyDateDeserializer.java
com.buddy.sdk.BuddyFile.java
com.buddy.sdk.BuddyFutureCallback.java
com.buddy.sdk.BuddyFuture.java
com.buddy.sdk.BuddyLocationDeserializer.java
com.buddy.sdk.BuddyLocationRangeSerializer.java
com.buddy.sdk.BuddyLocationSerializer.java
com.buddy.sdk.BuddyResultBase.java
com.buddy.sdk.BuddyResult.java
com.buddy.sdk.BuddyServiceClient.java
com.buddy.sdk.Buddy.java
com.buddy.sdk.DateRangeSerializer.java
com.buddy.sdk.DateRange.java
com.buddy.sdk.JsonEnvelopeBase.java
com.buddy.sdk.JsonEnvelopeDeserializer.java
com.buddy.sdk.JsonEnvelope.java
com.buddy.sdk.UserAuthenticationRequiredCallback.java
com.buddy.sdk.models.AlbumItem.java
com.buddy.sdk.models.Album.java
com.buddy.sdk.models.BinaryModelBase.java
com.buddy.sdk.models.Blob.java
com.buddy.sdk.models.BuddyLocation.java
com.buddy.sdk.models.Checkin.java
com.buddy.sdk.models.Identity.java
com.buddy.sdk.models.LocationRange.java
com.buddy.sdk.models.Message.java
com.buddy.sdk.models.MetadataItem.java
com.buddy.sdk.models.ModelBase.java
com.buddy.sdk.models.NotificationResult.java
com.buddy.sdk.models.PagedResult.java
com.buddy.sdk.models.Picture.java
com.buddy.sdk.models.SocialNetworkUser.java
com.buddy.sdk.models.TimedMetric.java
com.buddy.sdk.models.UserListItem.java
com.buddy.sdk.models.UserList.java
com.buddy.sdk.models.User.java
com.buddy.sdk.models.Video.java