@Override public String[] getCallbackIP() throws WxErrorException { String url = "https://api.weixin.qq.com/cgi-bin/getcallbackip"; String responseContent = get(url, null); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonArray ipList = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); String[] ipArray = new String[ipList.size()]; for (int i = 0; i < ipList.size(); i++) { ipArray[i] = ipList.get(i).getAsString(); } return ipArray; }
@Override public Filters deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject j = json.getAsJsonObject(); final JsonElement filters = j.get(KEY_FILTERS); if (null == filters) { throw new JsonParseException("Missing filters array!"); } final ArrayList<DashboardFilter> viewFilters = new ArrayList<>(); filters.getAsJsonArray().forEach((f) -> viewFilters.add(context.deserialize(f, DashboardFilter.class))); return new Filters(viewFilters); } }
@Override public SetMultimap<String, V> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { SetMultimap<String, V> result = HashMultimap.create(); JsonObject obj = json.getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { if (entry.getValue().isJsonArray()) { for (JsonElement item : entry.getValue().getAsJsonArray()) { result.put(entry.getKey(), context.<V>deserialize(item, valueType)); } } else { result.put(entry.getKey(), context.<V>deserialize(entry.getValue(), valueType)); } } return result; }
protected <T, K> Hit<T, K> extractHit(Class<T> sourceType, Class<K> explanationType, JsonElement hitElement, String sourceKey, boolean addEsMetadataFields) { Hit<T, K> hit = null; if (hitElement.isJsonObject()) { JsonObject hitObject = hitElement.getAsJsonObject(); JsonObject source = hitObject.getAsJsonObject(sourceKey); String index = hitObject.get("_index").getAsString(); String type = hitObject.get("_type").getAsString(); String id = hitObject.get("_id").getAsString(); if (hitObject.has("matched_queries") && !hitObject.get("matched_queries").isJsonNull()) { JsonArray rawMatchedQueries = hitObject.get("matched_queries").getAsJsonArray(); rawMatchedQueries.forEach(matchedQuery -> { matchedQueries.add(matchedQuery.getAsString());
public EnumConverter(JsonSchema schema, String namespace) { super(schema); JsonObject dataType = schema.getDataType(); for (JsonElement elem : dataType.get(ENUM_SYMBOLS_KEY).getAsJsonArray()) { this.enumSet.add(elem.getAsString()); } String enumName = schema.getName(); this.enumName = enumName.isEmpty() ? null : enumName; this.namespace = namespace; }
public DateRangeAggregation(String name, JsonObject dateRangeAggregation) { super(name, dateRangeAggregation); if (dateRangeAggregation.has(String.valueOf(BUCKETS)) && dateRangeAggregation.get(String.valueOf(BUCKETS)).isJsonArray()) { parseBuckets(dateRangeAggregation.get(String.valueOf(BUCKETS)).getAsJsonArray()); } }
@Test public void schemaWithUnion() throws Exception { String testName = "schemaWithUnion"; JsonObject schema = getSchemaData(testName).getAsJsonObject(); JsonArray expected = getExpectedSchema(testName).getAsJsonArray(); UnionConverter converter = new UnionConverter(new JsonSchema(schema), state); Assert.assertEquals(avroSchemaToJsonElement(converter), expected); }
/** * * @return empty array if response is not present, otherwise column names as first row plus one additional row per single result */ public String[][] getPlainText() { JsonObject jsonObject = getJsonObject(); if (jsonObject != null && getPathToResult() != null && jsonObject.has(getPathToResult()) && jsonObject.get(getPathToResult()).isJsonArray()) { JsonArray esResultRows = jsonObject.get(getPathToResult()).getAsJsonArray(); if(esResultRows.size() > 0 && esResultRows.get(0).isJsonObject()) { return parseResultArray(esResultRows); } } return new String[0][0]; }
public static boolean isNotNullOrEmpty(ValidationErrors validationErrors, Object name, JsonElement value) { if (value == null) { validationErrors.addErrorMessage(name + " may not be null."); return false; } if (value.isJsonNull()) { validationErrors.addErrorMessage(name + " may not be empty."); return false; } if (value.isJsonArray() && value.getAsJsonArray().size() < 1) { validationErrors.addErrorMessage(name + " may not be an empty array."); return false; } if (!value.isJsonObject() && value.getAsString().isEmpty()) { validationErrors.addErrorMessage(name + " may not be empty."); return false; } return true; }
private JsonElement getSchemaData(String methodName) { return testData.get(methodName).getAsJsonArray().get(0); } }
private void processSingleRequestResponse(CloseableHttpResponse response) throws IOException, UnexpectedResponseException { int statusCode = response.getStatusLine().getStatusCode(); if (statusCode < 400) { return; } String entityStr = EntityUtils.toString(response.getEntity()); if (statusCode == 400 && Operation.INSERT_ONLY_NOT_EXIST.equals(operation) && entityStr != null) { //Ignore if it's duplicate entry error code JsonArray jsonArray = new JsonParser().parse(entityStr).getAsJsonArray(); JsonObject jsonObject = jsonArray.get(0).getAsJsonObject(); if (isDuplicate(jsonObject, statusCode)) { return; } } throw new RuntimeException("Failed due to " + entityStr + " (Detail: " + ToStringBuilder.reflectionToString(response, ToStringStyle.SHORT_PREFIX_STYLE) + " )"); }
JsonArray array = element.getAsJsonArray(); List<Object> result = new ArrayList<>(array.size()); for (JsonElement item : array) { result.add(gson.fromJson(item, itemType)); Class<?> valueType = fieldBinding.singleAdapter().javaType; JsonObject object = element.getAsJsonObject(); Map<Object, Object> result = new LinkedHashMap<>(object.size()); for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
@Override public Quat4f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonArray()) { JsonArray array = json.getAsJsonArray(); if (array.size() == 4) { return new Quat4f(array.get(0).getAsFloat(), array.get(1).getAsFloat(), array.get(2).getAsFloat(), array.get(3).getAsFloat()); } } return null; } }
/** * Get source.schema within a {@link InputType#RECORD} type. * The source.schema is represented by a {@link JsonArray} * @return */ public JsonArray getDataTypeValues() { if (this.type.equals(RECORD)) { return getDataType().get(RECORD_FIELDS_KEY).getAsJsonArray(); } return new JsonArray(); }
@Override public BlockVector3 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonArray jsonArray = json.getAsJsonArray(); if (jsonArray.size() != 3) { throw new JsonParseException("Expected array of 3 length for BlockVector3"); } double x = jsonArray.get(0).getAsInt(); double y = jsonArray.get(1).getAsInt(); double z = jsonArray.get(2).getAsInt(); return BlockVector3.at(x, y, z); } }
@Override public EntityData.Value deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { EntityData.Value.Builder value = EntityData.Value.newBuilder(); if (json.isJsonPrimitive()) { extractPrimitive(value, json); } else if (json.isJsonObject()) { extractMap(json, context, value); } else if (json.isJsonArray()) { JsonArray jsonArray = json.getAsJsonArray(); TByteList byteList = new TByteArrayList(); for (JsonElement element : jsonArray) { if (element.isJsonArray()) { value.addValue((EntityData.Value) context.deserialize(element, EntityData.Value.class)); } else if (element.isJsonObject()) { value.addValue((EntityData.Value) context.deserialize(element, EntityData.Value.class)); } else if (element.isJsonPrimitive()) { extractPrimitive(value, element); if (element.getAsJsonPrimitive().isNumber()) { try { byteList.add(element.getAsByte()); } catch (NumberFormatException nfe) { byteList.add((byte) 0); } } } } value.setBytes(ByteString.copyFrom(byteList.toArray())); } return value.build(); }
@Override public String[] getCallbackIp() throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/getcallbackip"; String responseContent = get(url, null); JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent))); JsonArray jsonArray = tmpJsonElement.getAsJsonObject().get("ip_list").getAsJsonArray(); String[] ips = new String[jsonArray.size()]; for(int i = 0; i < jsonArray.size(); i++) { ips[i] = jsonArray.get(i).getAsString(); } return ips; }
public RangeAggregation(String name, JsonObject rangeAggregation) { super(name, rangeAggregation); ranges = new ArrayList<Range>(); //todo support keyed:true as well for (JsonElement bucketElement : rangeAggregation.get(String.valueOf(BUCKETS)).getAsJsonArray()) { JsonObject bucket = bucketElement.getAsJsonObject(); Range range = new Range( bucket, bucket.has(String.valueOf(FROM)) ? bucket.get(String.valueOf(FROM)).getAsDouble() : null, bucket.has(String.valueOf(TO)) ? bucket.get(String.valueOf(TO)).getAsDouble() : null, bucket.get(String.valueOf(DOC_COUNT)).getAsLong()); ranges.add(range); } }
throws JsonParseException { List<JobExecutionPlan> jobExecutionPlans = new ArrayList<>(); JsonArray jsonArray = json.getAsJsonArray(); JsonObject jobSpecJson = (JsonObject) serializedJobExecutionPlan.get(SerializationConstants.JOB_SPEC_KEY); JsonObject specExecutorJson = (JsonObject) serializedJobExecutionPlan.get(SerializationConstants.SPEC_EXECUTOR_KEY); ExecutionStatus executionStatus = ExecutionStatus.valueOf(serializedJobExecutionPlan. get(SerializationConstants.EXECUTION_STATUS_KEY).getAsString()); String uri = jobSpecJson.get(SerializationConstants.JOB_SPEC_URI_KEY).getAsString(); String version = jobSpecJson.get(SerializationConstants.JOB_SPEC_VERSION_KEY).getAsString(); String description = jobSpecJson.get(SerializationConstants.JOB_SPEC_DESCRIPTION_KEY).getAsString(); String templateURI = jobSpecJson.get(SerializationConstants.JOB_SPEC_TEMPLATE_URI_KEY).getAsString();
public HistogramAggregation(String name, JsonObject histogramAggregation) { super(name, histogramAggregation); if(histogramAggregation.has(String.valueOf(BUCKETS)) && histogramAggregation.get(String.valueOf(BUCKETS)).isJsonArray()) { parseBuckets(histogramAggregation.get(String.valueOf(BUCKETS)).getAsJsonArray()); } }