Search in sources :

Example 21 with Gson

use of com.google.gson.Gson in project weixin-java-tools by chanjarster.

the class WxMenuGsonAdapter method serialize.

public JsonElement serialize(WxMenu menu, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject json = new JsonObject();
    JsonArray buttonArray = new JsonArray();
    for (WxMenu.WxMenuButton button : menu.getButtons()) {
        JsonObject buttonJson = convertToJson(button);
        buttonArray.add(buttonJson);
    }
    json.add("button", buttonArray);
    if (menu.getMatchRule() != null) {
        Gson gson = new Gson();
        json.add("matchrule", gson.toJsonTree(menu.getMatchRule()));
    }
    return json;
}
Also used : JsonArray(com.google.gson.JsonArray) WxMenu(me.chanjar.weixin.common.bean.WxMenu) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson)

Example 22 with Gson

use of com.google.gson.Gson in project kickmaterial by byoutline.

the class GlobalModule method providesGson.

@Provides
Gson providesGson() {
    GsonBuilder builder = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    JsonDeserializer<DateTime> deserializer = (json, typeOfT, context) -> new DateTime(json.getAsJsonPrimitive().getAsLong() * 1000);
    builder.registerTypeAdapter(DateTime.class, deserializer);
    return builder.create();
}
Also used : OttoObservableCachedFieldWithArgBuilder(com.byoutline.ottocachedfield.OttoObservableCachedFieldWithArgBuilder) Bus(com.squareup.otto.Bus) CachedField(com.byoutline.cachedfield.CachedField) GsonBuilder(com.google.gson.GsonBuilder) KickMaterialService(com.byoutline.kickmaterial.api.KickMaterialService) KickMaterialRequestInterceptor(com.byoutline.kickmaterial.api.KickMaterialRequestInterceptor) Picasso(com.squareup.picasso.Picasso) FieldNamingPolicy(com.google.gson.FieldNamingPolicy) Module(dagger.Module) ObservableCachedFieldWithArg(com.byoutline.observablecachedfield.ObservableCachedFieldWithArg) Gson(com.google.gson.Gson) RetrofitHelper.apiValueProv(com.byoutline.ibuscachedfield.util.RetrofitHelper.apiValueProv) GsonConverterFactory(retrofit2.converter.gson.GsonConverterFactory) OttoCachedFieldBuilder(com.byoutline.ottocachedfield.OttoCachedFieldBuilder) KickMaterialApp(com.byoutline.kickmaterial.KickMaterialApp) LruCacheWithPlaceholders(com.byoutline.kickmaterial.utils.LruCacheWithPlaceholders) Nullable(javax.annotation.Nullable) Provides(dagger.Provides) CachedFieldWithArg(com.byoutline.cachedfield.CachedFieldWithArg) com.byoutline.kickmaterial.events(com.byoutline.kickmaterial.events) AccessTokenProvider(com.byoutline.kickmaterial.managers.AccessTokenProvider) DateTime(org.joda.time.DateTime) LoginManager(com.byoutline.kickmaterial.managers.LoginManager) Retrofit(retrofit2.Retrofit) List(java.util.List) OkHttpClient(okhttp3.OkHttpClient) SharedPreferences(android.content.SharedPreferences) JsonDeserializer(com.google.gson.JsonDeserializer) com.byoutline.kickmaterial.model(com.byoutline.kickmaterial.model) OttoCachedFieldWithArgBuilder(com.byoutline.ottocachedfield.OttoCachedFieldWithArgBuilder) GsonBuilder(com.google.gson.GsonBuilder) DateTime(org.joda.time.DateTime) Provides(dagger.Provides)

Example 23 with Gson

use of com.google.gson.Gson in project weave by continuuity.

the class YarnWeaveRunnerService method getApplicationId.

/**
   * Decodes application ID stored inside the node data.
   * @param nodeData The node data to decode from. If it is {@code null}, this method would return {@code null}.
   * @return The ApplicationId or {@code null} if failed to decode.
   */
private ApplicationId getApplicationId(NodeData nodeData) {
    byte[] data = nodeData == null ? null : nodeData.getData();
    if (data == null) {
        return null;
    }
    Gson gson = new Gson();
    JsonElement json = gson.fromJson(new String(data, Charsets.UTF_8), JsonElement.class);
    if (!json.isJsonObject()) {
        LOG.warn("Unable to decode live data node.");
        return null;
    }
    JsonObject jsonObj = json.getAsJsonObject();
    json = jsonObj.get("data");
    if (!json.isJsonObject()) {
        LOG.warn("Property data not found in live data node.");
        return null;
    }
    try {
        ApplicationMasterLiveNodeData amLiveNode = gson.fromJson(json, ApplicationMasterLiveNodeData.class);
        return YarnUtils.createApplicationId(amLiveNode.getAppIdClusterTime(), amLiveNode.getAppId());
    } catch (Exception e) {
        LOG.warn("Failed to decode application live node data.", e);
        return null;
    }
}
Also used : JsonElement(com.google.gson.JsonElement) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) ApplicationMasterLiveNodeData(com.continuuity.weave.internal.appmaster.ApplicationMasterLiveNodeData) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 24 with Gson

use of com.google.gson.Gson in project cryptomator by cryptomator.

the class WelcomeController method checkForUpdates.

private void checkForUpdates() {
    checkForUpdatesStatus.setText(localization.getString("welcome.checkForUpdates.label.currentlyChecking"));
    checkForUpdatesIndicator.setVisible(true);
    asyncTaskService.asyncTaskOf(() -> {
        RequestConfig requestConfig = //
        RequestConfig.custom().setConnectTimeout(//
        5000).setConnectionRequestTimeout(//
        5000).setSocketTimeout(//
        5000).build();
        HttpClientBuilder httpClientBuilder = //
        HttpClients.custom().disableCookieManagement().setDefaultRequestConfig(//
        requestConfig).setUserAgent("Cryptomator VersionChecker/" + ApplicationVersion.orElse("SNAPSHOT"));
        LOG.debug("Checking for updates...");
        try (CloseableHttpClient client = httpClientBuilder.build()) {
            HttpGet request = new HttpGet("https://cryptomator.org/downloads/latestVersion.json");
            try (CloseableHttpResponse response = client.execute(request)) {
                if (response.getStatusLine().getStatusCode() == 200 && response.getEntity() != null) {
                    try (InputStream in = response.getEntity().getContent()) {
                        Gson gson = new GsonBuilder().setLenient().create();
                        Reader utf8Reader = new InputStreamReader(in, StandardCharsets.UTF_8);
                        Map<String, String> map = gson.fromJson(utf8Reader, new TypeToken<Map<String, String>>() {
                        }.getType());
                        if (map != null) {
                            this.compareVersions(map);
                        }
                    }
                }
            }
        }
    }).andFinally(() -> {
        checkForUpdatesStatus.setText("");
        checkForUpdatesIndicator.setVisible(false);
    }).run();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) InputStreamReader(java.io.InputStreamReader) GsonBuilder(com.google.gson.GsonBuilder) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Gson(com.google.gson.Gson) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) TypeToken(com.google.gson.reflect.TypeToken) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 25 with Gson

use of com.google.gson.Gson in project UltimateAndroid by cymcsg.

the class JsonUtil method getObjectFromJson.

public static Object getObjectFromJson(String jsonString) {
    Gson gson = new Gson();
    Object object = gson.fromJson(jsonString, Object.class);
    return object;
}
Also used : Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)1060 Test (org.junit.Test)236 HashMap (java.util.HashMap)200 JsonObject (com.google.gson.JsonObject)138 GsonBuilder (com.google.gson.GsonBuilder)135 CommandWrapper (ClientServerApi.CommandWrapper)123 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 IOException (java.io.IOException)116 JsonSyntaxException (com.google.gson.JsonSyntaxException)100 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 ArrayList (java.util.ArrayList)94 Type (java.lang.reflect.Type)65 JsonElement (com.google.gson.JsonElement)57 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 Map (java.util.Map)45 InputStreamReader (java.io.InputStreamReader)41 BroadcastClientMessage (org.bigbluebutton.red5.client.messaging.BroadcastClientMessage)41 Location (BasicCommonClasses.Location)40