JsonObject innerObject = new JsonObject(); innerObject.addProperty("name", "john"); JsonObject jsonObject = new JsonObject(); jsonObject.add("publisher", innerObject);
public String toJson() { JsonObject details = new JsonObject(); details.addProperty(FIELD_LEVEL, level.toString()); JsonArray conditionResults = new JsonArray(); for (EvaluatedCondition condition : this.conditions) { conditionResults.add(toJson(condition)); } details.add("conditions", conditionResults); details.addProperty(FIELD_IGNORED_CONDITIONS, ignoredConditions); return details.toString(); }
public JsonObject toJsonObject() { JsonObject sortDefinition = new JsonObject(); if (order != null) { sortDefinition.add("order", new JsonPrimitive(order.toString())); } if (missing != null) { sortDefinition.add("missing", new JsonPrimitive(missing.toString())); } if (unmapped != null) { sortDefinition.add("ignore_unmapped", new JsonPrimitive(unmapped)); } if(unmappedType != null) { sortDefinition.add("unmapped_type", new JsonPrimitive(unmappedType)); } JsonObject sortObject = new JsonObject(); sortObject.add(field, sortDefinition); return sortObject; }
public StoolConfiguration createPatched(Gson gson, String str) { JsonObject changes; JsonObject dest; dest = (JsonObject) gson.toJsonTree(this); changes = new JsonParser().parse(str).getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : changes.entrySet()) { if (!dest.has(entry.getKey())) { throw new IllegalStateException("unknown property: " + entry.getKey()); } dest.add(entry.getKey(), entry.getValue()); } return gson.fromJson(dest, StoolConfiguration.class); }
JsonSerializationContext context) { JsonObject retValue = new JsonObject(); String className = src.getClass().getName(); retValue.addProperty(CLASSNAME, className); JsonElement elem = context.serialize(src); retValue.add(INSTANCE, elem); return retValue; public IAnimal deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); JsonPrimitive prim = (JsonPrimitive) jsonObject.get(CLASSNAME); String className = prim.getAsString(); throw new JsonParseException(e.getMessage()); return context.deserialize(jsonObject.get(INSTANCE), klass);
JsonParser parser = new JsonParser(); JsonElement e = parser.parse(jsonString); JsonObject o = e.getAsJsonObject(); String rptValue = o.get(RPT).getAsString(); incomingRpt = tokenService.readAccessToken(rptValue); String ticketValue = o.get(TICKET).getAsString(); JsonObject entity = new JsonObject(); entity.addProperty(JsonErrorView.ERROR, "need_info"); JsonObject details = new JsonObject(); c.add("claim_token_format", f); JsonArray i = new JsonArray(); for (String issuer : claim.getIssuer()) { i.add(new JsonPrimitive(issuer)); c.add("issuer", i); req.add(c); rpClaims.add("required_claims", req); details.add("requesting_party_claims", rpClaims); entity.add("error_details", details);
@VisibleForTesting JsonObject createOutput(JsonArray outputSchema, String inputRecord) throws DataConversionException { JsonObject outputRecord = new JsonObject(); JsonElement capturesJson = JSON_PARSER.parse(gm.toJson()); JsonObject outputSchemaJsonObject = anOutputSchema.getAsJsonObject(); String key = outputSchemaJsonObject.get(COLUMN_NAME_KEY).getAsString(); String type = outputSchemaJsonObject.getAsJsonObject(DATA_TYPE).get(TYPE_KEY).getAsString(); if (!outputSchemaJsonObject.get(NULLABLE).getAsBoolean()) { throw new DataConversionException( "Field " + key + " is null or not exists but it is non-nullable by the schema."); outputRecord.add(key, JsonNull.INSTANCE); } else { JsonElement jsonElement = capturesJson.getAsJsonObject().get(key); switch (type) { case "int": outputRecord.addProperty(key, jsonElement.getAsInt()); break; case "long": outputRecord.addProperty(key, jsonElement.getAsLong()); break; case "double": outputRecord.addProperty(key, jsonElement.getAsDouble()); break; case "float":
private static void addPatternListToSource(JsonObject sourceObject, String rule, List<String> patternList) { if (!patternList.isEmpty()) { JsonArray ruleArray; if (sourceObject.has(rule)) { ruleArray = sourceObject.get(rule).getAsJsonArray(); } else { ruleArray = new JsonArray(); sourceObject.add(rule, ruleArray); } for (String pattern : patternList) { ruleArray.add(pattern); } } }
private static JsonArray normalizeSortClause(JsonObject queryObject) { JsonArray sortArray; if (queryObject.has("sort")) { JsonElement sortElement = queryObject.get("sort"); if (sortElement.isJsonArray()) { sortArray = sortElement.getAsJsonArray(); } else if (sortElement.isJsonObject()) { sortArray = new JsonArray(); sortArray.add(sortElement.getAsJsonObject()); } else if (sortElement.isJsonPrimitive() && sortElement.getAsJsonPrimitive().isString()) { String sortField = sortElement.getAsString(); sortArray = new JsonArray(); queryObject.add("sort", sortArray); String order; if ("_score".equals(sortField)) { order = "asc"; JsonObject sortOrder = new JsonObject(); sortOrder.add("order", new JsonPrimitive(order)); JsonObject sortDefinition = new JsonObject(); sortDefinition.add(sortField, sortOrder); sortArray = new JsonArray(); queryObject.add("sort", sortArray);
JsonObject root = new JsonObject(); if (!jsonObject.has(COLUMN_NAME_KEY) && !jsonObject.has(DATA_TYPE_KEY)) { root.addProperty(COLUMN_NAME_KEY, DEFAULT_RECORD_COLUMN_NAME); root.add(DATA_TYPE_KEY, jsonObject); jsonObject = root; jsonObject.addProperty(COLUMN_NAME_KEY, DEFAULT_RECORD_COLUMN_NAME); JsonElement typeElement = getDataType().get(TYPE_KEY); if (typeElement.isJsonPrimitive()) { this.type = Type.valueOf(typeElement.getAsString().toUpperCase()); this.firstType = buildBaseSchema(type1.getAsJsonObject()); this.secondType = buildBaseSchema(type2.getAsJsonObject()); JsonArray jsonArray = new JsonArray(); jsonArray.add(jsonObject); this.jsonArray = jsonArray; this.schemaNestedLevel = CHILD;
if (storedString != null && storedString.startsWith("{")) { try { jsonElement = new JsonParser().parse(storedString); } catch (JsonSyntaxException ex) { jsonElement = new JsonPrimitive(storedString == null ? "" : storedString); jsonElement = new JsonPrimitive(""); JsonObject jsonTextObject = new JsonObject(); jsonTextObject.add("text", jsonElement); values.put("Text" + (i + 1), new StringTag(jsonTextObject.toString()));
@Override public void write(JsonWriter out, R value) throws IOException { Class<?> srcType = value.getClass(); String label = subtypeToLabel.get(srcType); @SuppressWarnings("unchecked") // registration requires that subtype extends T TypeAdapter<R> delegate = (TypeAdapter<R>) subtypeToDelegate.get(srcType); if (delegate == null) { throw new JsonParseException("cannot serialize " + srcType.getName() + "; did you forget to register a subtype?"); } JsonObject jsonObject = delegate.toJsonTree(value).getAsJsonObject(); if (jsonObject.has(typeFieldName) && !srcType.getSimpleName().equals("OldInput")) { throw new JsonParseException("cannot serialize " + srcType.getName() + " because it already defines a field named " + typeFieldName); } JsonObject clone = new JsonObject(); if (!srcType.getSimpleName().equals("OldInput")) { clone.add(typeFieldName, new JsonPrimitive(label)); } for (Map.Entry<String, JsonElement> e : jsonObject.entrySet()) { clone.add(e.getKey(), e.getValue()); } Streams.write(clone, out); } }.nullSafe();
kunderaMetadata); String _id = object.get("_id").getAsString(); JsonObject jsonObject = gson.fromJson(reader, JsonObject.class); JsonElement rev = jsonObject.get("_rev"); object.add("_rev", rev); object.addProperty("_id", entityMetadata.getTableName() + id); stringEntity = new StringEntity(object.toString(), Constants.CHARSET_UTF8); stringEntity.setContentType("application/json");
private static void merge(JsonObject target, JsonObject from) { for (Map.Entry<String, JsonElement> entry : from.entrySet()) { if (entry.getValue().isJsonObject()) { if (target.has(entry.getKey()) && target.get(entry.getKey()).isJsonObject()) { merge(target.get(entry.getKey()).getAsJsonObject(), entry.getValue().getAsJsonObject()); } else { target.remove(entry.getKey()); target.add(entry.getKey(), entry.getValue()); } } else { target.remove(entry.getKey()); target.add(entry.getKey(), entry.getValue()); } } }
private void addEnvironment(Properties envProps) { JsonArray containerEnv = new JsonArray(); Enumeration keys = envProps.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = envProps.getProperty(key); if (value == null) { value = ""; } containerEnv.add(key + "=" + value); } createConfig.add("Env", containerEnv); }
@Override public JsonElement serialize(List<PipelineConfigs> src, Type typeOfSrc, JsonSerializationContext context) { JsonObject serialized = new JsonObject(); for (PipelineConfigs group : src) { final List<PipelineConfig> pipelines = group.getPipelines(); if (!pipelines.isEmpty()) { List<CaseInsensitiveString> pipelineNames = pipelines.stream().map(PipelineConfig::name).collect(Collectors.toList()); serialized.add(group.getGroup(), context.serialize(pipelineNames)); } } return serialized; } }
@Override public T read(JsonReader in) throws IOException { JsonObject jobj = new JsonParser().parse(in).getAsJsonObject(); if (jobj.has("parameters") && jobj.get("parameters").isJsonArray()) { JsonArray jarr = jobj.get("parameters").getAsJsonArray(); JsonObject paramsNew = new JsonObject(); for (JsonElement item : jarr) { JsonObject itemObj = item.getAsJsonObject(); paramsNew.add(itemObj.get("name").getAsString(), itemObj.get("actual_value")); } jobj.add("parameters", paramsNew); } // noinspection unchecked return (T) new Gson().fromJson(jobj, rawType); } };
@Override public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorException { String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers"; JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("tagid", tagId); JsonArray jsonArray = new JsonArray(); for (String userId : userIds) { jsonArray.add(new JsonPrimitive(userId)); } jsonObject.add("userlist", jsonArray); post(url, jsonObject.toString()); }
@VisibleForTesting JsonObject createOutput(JsonArray outputSchema, String[] inputRecord) { Preconditions.checkArgument(outputSchema.size() == inputRecord.length, "# of columns mismatch. Input " + inputRecord.length + " , output: " + outputSchema.size()); JsonObject outputRecord = new JsonObject(); for (int i = 0; i < outputSchema.size(); i++) { JsonObject field = outputSchema.get(i).getAsJsonObject(); String key = field.get(COLUMN_NAME_KEY).getAsString(); if (StringUtils.isEmpty(inputRecord[i]) || JSON_NULL_VAL.equalsIgnoreCase(inputRecord[i])) { outputRecord.add(key, JsonNull.INSTANCE); } else { outputRecord.add(key, convertValue(inputRecord[i], field.getAsJsonObject(DATA_TYPE_KEY))); } } return outputRecord; }
String createAgentRequestBody(String autoRegisterKey, String environment, Map<String, String> configuration, JobIdentifier jobIdentifier) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("auto_register_key", autoRegisterKey); jsonObject.add("properties", mapToJsonObject(configuration)); jsonObject.addProperty("environment", environment); jsonObject.add("job_identifier", jobIdentifierJson(jobIdentifier)); return GSON.toJson(jsonObject); }