private String toJSON(Map<String, String> settingsMap) { return new GsonBuilder().serializeNulls().create().toJson(settingsMap); }
public RequestHandler(Context context) { mContext = context; mAssets = context.getResources().getAssets(); mGson = new GsonBuilder().serializeNulls().create(); }
private static String pretty(String json) { JsonElement gson = new JsonParser().parse(json); return new GsonBuilder().setPrettyPrinting().serializeNulls().create().toJson(gson); } }
String validateElasticProfileRequestBody(Map<String, String> configuration) { JsonObject properties = mapToJsonObject(configuration); return new GsonBuilder().serializeNulls().create().toJson(properties); }
String validateElasticProfileRequestBody(Map<String, String> configuration) { JsonObject properties = mapToJsonObject(configuration); return new GsonBuilder().serializeNulls().create().toJson(properties); }
public String createRequest() { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().serializeNulls().create(); return gson.toJson(this.transformData()); } }
@Override public void afterPropertiesSet() { GsonBuilder builder = (this.base64EncodeByteArrays ? GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder()); if (this.serializeNulls) { builder.serializeNulls(); } if (this.prettyPrinting) { builder.setPrettyPrinting(); } if (this.disableHtmlEscaping) { builder.disableHtmlEscaping(); } if (this.dateFormatPattern != null) { builder.setDateFormat(this.dateFormatPattern); } this.gson = builder.create(); }
@Override public void afterPropertiesSet() { GsonBuilder builder = (this.base64EncodeByteArrays ? GsonBuilderUtils.gsonBuilderWithBase64EncodedByteArrays() : new GsonBuilder()); if (this.serializeNulls) { builder.serializeNulls(); } if (this.prettyPrinting) { builder.setPrettyPrinting(); } if (this.disableHtmlEscaping) { builder.disableHtmlEscaping(); } if (this.dateFormatPattern != null) { builder.setDateFormat(this.dateFormatPattern); } this.gson = builder.create(); }
private static Gson gsonBuilder(final GoRequestContext requestContext) { GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapter(JsonUrl.class, (JsonSerializer<JsonUrl>) (src, typeOfSrc, context) -> { if (requestContext == null) { return new JsonPrimitive(src.getUrl()); } else { return new JsonPrimitive(requestContext.getFullRequestPath() + src.getUrl()); } }); builder.registerTypeHierarchyAdapter(MessageSourceResolvable.class, (JsonSerializer<MessageSourceResolvable>) (src, typeOfSrc, context) -> { if (requestContext == null) { return new JsonPrimitive(src.getDefaultMessage()); } else { return new JsonPrimitive(requestContext.getMessage(src)); } }); builder.serializeNulls(); return builder.create(); } }
private Api() { HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor(); logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); File cacheFile = new File(App.getAppContext().getCacheDir(), "cache"); Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb OkHttpClient okHttpClient = new OkHttpClient.Builder() .readTimeout(7676, TimeUnit.MILLISECONDS) .connectTimeout(7676, TimeUnit.MILLISECONDS) .addInterceptor(headInterceptor) .addInterceptor(logInterceptor) .addNetworkInterceptor(new HttpCacheInterceptor()) .cache(cache) .build(); Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create(); retrofit = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create(gson)) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .baseUrl(C.BASE_URL) .build(); service = retrofit.create(ApiService.class); }
.build(); Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create(); retrofit = new Retrofit.Builder() .client(okHttpClient)
Gson gson = new GsonBuilder().serializeNulls().serializeSpecialFloatingPointValues().create(); responseMsg = gson.toJson(respMap); } else {
private String getJSONString(CruiseControlParameters parameters) { Map<String, Object> optimizationResult = new HashMap<>(); if (((KafkaOptimizationParameters) parameters).isVerbose()) { optimizationResult.put(PROPOSALS, _optimizerResult.goalProposals().stream() .map(ExecutionProposal::getJsonStructure).collect(Collectors.toSet())); optimizationResult.put(LOAD_BEFORE_OPTIMIZATION, _optimizerResult.brokerStatsBeforeOptimization().getJsonStructure()); } optimizationResult.put(SUMMARY, _optimizerResult.getProposalSummaryForJson()); List<Map<String, Object>> goalSummary = new ArrayList<>(); for (Map.Entry<String, ClusterModelStats> entry : _optimizerResult.statsByGoalName().entrySet()) { String goalName = entry.getKey(); Map<String, Object> goalMap = new HashMap<>(); goalMap.put(GOAL, goalName); goalMap.put(STATUS, goalResultDescription(goalName)); goalMap.put(CLUSTER_MODEL_STATS, entry.getValue().getJsonStructure()); goalSummary.add(goalMap); } optimizationResult.put(GOAL_SUMMARY, goalSummary); optimizationResult.put(LOAD_AFTER_OPTIMIZATION, _optimizerResult.brokerStatsAfterOptimization().getJsonStructure()); optimizationResult.put(VERSION, JSON_VERSION); Gson gson = new GsonBuilder().serializeNulls().serializeSpecialFloatingPointValues().create(); return gson.toJson(optimizationResult); }
.serializeNulls() .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") .create();
.serializeNulls() .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") .create();
.serializeNulls() .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ") .create();
.serializeNulls() .registerTypeAdapter(JWSAlgorithm.class, new JsonDeserializer<Algorithm>() { @Override
Gson gson = new GsonBuilder().registerTypeAdapter(JdbcEntryData.class, serializer).serializeNulls().create();
@Test public void propagateGsonAttributes() { Gson gson = new GsonBuilder() .serializeNulls() .disableHtmlEscaping() .setPrettyPrinting() .create(); GsonOptions options = new GsonOptions(gson, true); JsonReader reader = new JsonReader(new StringReader("")); options.setReaderOptions(reader); check(reader.isLenient()); JsonWriter writer = new JsonWriter(new StringWriter()); options.setWriterOptions(writer); check(writer.isLenient()); check(!writer.isHtmlSafe()); check(writer.getSerializeNulls()); // checks pretty printing check(gson.toJson(Collections.singletonMap("k", "v"))).is("{\n \"k\": \"v\"\n}"); } }
@VisibleForTesting public HttpMultiRollupsQueryHandler(BatchedMetricsOutputSerializer<JSONObject> serializer) { Configuration config = Configuration.getInstance(); int maxThreadsToUse = config.getIntegerProperty(HttpConfig.MAX_READ_WORKER_THREADS); int maxQueueSize = config.getIntegerProperty(HttpConfig.MAX_BATCH_READ_REQUESTS_TO_QUEUE); this.maxMetricsPerRequest = config.getIntegerProperty(HttpConfig.MAX_METRICS_PER_BATCH_QUERY); this.serializer = serializer; this.gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); this.parser = new JsonParser(); this.executor = new ThreadPoolBuilder().withCorePoolSize(maxThreadsToUse).withMaxPoolSize(maxThreadsToUse) .withName("HTTP-BatchMetricsFetch").withBoundedQueue(maxQueueSize).build(); }