private Map<String, String> mapLabels(JsonObject labels) { int length = labels.size(); Map<String, String> mapped = new HashMap<>(length); Iterator<String> iterator = labels.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); mapped.put(key, labels.get(key).getAsString()); } return mapped; } }
private Map<String, String> mapLabels(JsonObject labels) { int length = labels.size(); Map<String, String> mapped = new HashMap<>(length); Iterator<String> iterator = labels.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); mapped.put(key, labels.get(key).getAsString()); } return mapped; }
if (jsonObject.size() == 0) return null; return jsonObject.toString();
Map<Object, Object> result = new LinkedHashMap<>(object.size()); for (Map.Entry<String, JsonElement> entry : object.entrySet()) { Object key = gson.fromJson(entry.getKey(), keyType);
@Test public void protobufToJson_MessageWithMap_Success() throws Exception { // given FrameworkTest.MessageWithMap messageWithMap = FrameworkTest.MessageWithMap.newBuilder() .putErrorMap("first-error", FrameworkTest.Error.INVALID_VEHICLE_ID) .putErrorMap("second-error", FrameworkTest.Error.NO_ERROR) .build(); // when JsonObject jsonObject = ProtobufUtil.protobufToJson(messageWithMap); // then JsonObject error_map = jsonObject.getAsJsonObject("error_map"); assertThat(error_map.size()).isEqualTo(2); assertThat(error_map.getAsJsonPrimitive("first-error").getAsString()) .isEqualTo(FrameworkTest.Error.INVALID_VEHICLE_ID.toString()); assertThat(error_map.getAsJsonPrimitive("second-error").getAsString()) .isEqualTo(FrameworkTest.Error.NO_ERROR.toString()); }
public int size() { return this.dataCatcher.size(); }
public boolean isEmpty() { return this.dataCatcher.size() == 0; }
public int size() { return inner.size(); }
@Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { if (json.isJsonNull()) { return null; } else if (json.isJsonPrimitive()) { return json.getAsString(); } else if (json.isJsonObject() && json.getAsJsonObject().size() == 0) { /* * for some reason OpenWhisk passes an empty object on GET requests * if the Web Action is defined as "raw", even though it should pass a string! * => handle this case by returning null */ return null; } throw new IllegalStateException( "expected a string, null, or an empty object as request body but got" + this.getClass()); }
private static Map<String, Boolean> getReadOrWriteAccessDetails(String type, Map<String, Boolean> accessMap, String publicIp, String conditionStr, JsonObject conditionJsonObject, List<String> conditionList) { if ((conditionJsonObject.size() == 0) && (conditionList.isEmpty()) && null == conditionStr) { accessMap.put(type, true); } if (!conditionJsonObject.isJsonNull()) { if (conditionJsonObject.toString().equals(publicIp)) { accessMap.put(type, true); } } else if (null != conditionStr && conditionStr.contains(publicIp)) { accessMap.put(type, true); } else if (conditionList.contains(publicIp)) { accessMap.put(type, true); } return accessMap; }
@Override public void doBuildAndAddTo(ElasticsearchSearchSortCollector collector, JsonObject innerObject) { if ( innerObject.size() == 0 ) { collector.collectSort( SCORE_SORT_KEYWORD_JSON ); } else { JsonObject outerObject = new JsonObject(); outerObject.add( SCORE_SORT_KEYWORD, innerObject ); collector.collectSort( outerObject ); } } }
@Override public Collection<JsonElement> getPropertyNames(JsonElement value) { if (value.isJsonObject()) { JsonObject object = (JsonObject) value; List<JsonElement> names = new ArrayList<>((object.size())); for (String s : object.keySet()) { names.add(createString(s)); } return names; } else { return Collections.emptyList(); } }
@Override public void doBuildAndAddTo(ElasticsearchSearchSortCollector collector, JsonObject innerObject) { if ( innerObject.size() == 0 ) { collector.collectSort( SCORE_SORT_KEYWORD_JSON ); } else { JsonObject outerObject = new JsonObject(); outerObject.add( SCORE_SORT_KEYWORD, innerObject ); collector.collectSort( outerObject ); } } }
@Override public void doBuildAndAddTo(ElasticsearchSearchSortCollector collector, JsonObject innerObject) { if ( missing != null ) { MISSING.set( innerObject, missing ); } if ( innerObject.size() == 0 ) { collector.collectSort( new JsonPrimitive( absoluteFieldPath ) ); } else { JsonObject outerObject = new JsonObject(); outerObject.add( absoluteFieldPath, innerObject ); collector.collectSort( outerObject ); } } }
@Override public void doBuildAndAddTo(ElasticsearchSearchSortCollector collector, JsonObject innerObject) { if ( missing != null ) { MISSING.set( innerObject, missing ); } if ( innerObject.size() == 0 ) { collector.collectSort( new JsonPrimitive( absoluteFieldPath ) ); } else { JsonObject outerObject = new JsonObject(); outerObject.add( absoluteFieldPath, innerObject ); collector.collectSort( outerObject ); } } }
@Nullable @Override public OutputInfo deserialize( @NotNull JsonElement json, @NotNull TypeToken<OutputInfo> type, @NotNull Gson gson ) { final JsonObject root = assertJsonIs(json, JsonObject.class); if (root.has("message")) { return null; } if (root.has("type") && root.size() == 1) { return null; } return fromJson(gson, json, ModelType.determineModelType(root).infoType()); } };
public static String datumToJsonStr(CrawlDatum datum) { JsonArray jsonArray = new JsonArray(); jsonArray.add(datum.url()); jsonArray.add(datum.getStatus()); jsonArray.add(datum.getExecuteTime()); jsonArray.add(datum.getExecuteCount()); if (datum.meta().size() > 0) { jsonArray.add(datum.meta()); } return jsonArray.toString(); }
@Override protected ElasticsearchRequest buildRequest() { ElasticsearchRequest.Builder builder = ElasticsearchRequest.put() .pathComponent( indexName ); if ( payload.size() > 0 ) { builder.body( payload ); } return builder.build(); }
@Override protected ElasticsearchRequest buildRequest() { ElasticsearchRequest.Builder builder = ElasticsearchRequest.put() .pathComponent( indexName ); if ( payload.size() > 0 ) { builder.body( payload ); } return builder.build(); }
/** * Test for {@link KnownTypeAdapters#JSON_OBJECT} */ @Test public void testForJsonObjectTypeAdapter() throws Exception { JsonObject jsonObject = Utils.createDummyJsonObject(); TypeAdapter<JsonObject> jsonObjectTypeAdapter = KnownTypeAdapters.JSON_OBJECT; StringWriter stringWriter = new StringWriter(); jsonObjectTypeAdapter.write(new JsonWriter(stringWriter), jsonObject); String jsonString = stringWriter.toString(); JsonObject readValue = jsonObjectTypeAdapter.read(new JsonReader(new StringReader(jsonString))); assertEquals(jsonObject.size(), readValue.size()); }