/** * Creates a new empty JsonObject. This is equivalent to creating a new JsonObject using the * constructor. * * @return a new empty JSON object */ public static JsonObject object() { return new JsonObject(); }
@Override public JsonObject startObject() { return new JsonObject(); }
JsonObject getResults() { return new JsonObject(results); }
/** * Returns an unmodifiable JsonObject for the specified one. This method allows to provide * read-only access to a JsonObject. * <p> * The returned JsonObject is backed by the given object and reflect changes that happen to it. * Attempts to modify the returned JsonObject result in an * <code>UnsupportedOperationException</code>. * </p> * * @param object * the JsonObject for which an unmodifiable JsonObject is to be returned * @return an unmodifiable view of the specified JsonObject */ public static JsonObject unmodifiableObject(JsonObject object) { return new JsonObject(object, true); }
@Override protected void setUp() throws IOException { jsonObject = new JsonObject(); for (int index = 0; index < size; index++) { String name = Integer.toHexString(index); jsonObject.add(name, index); } }
private static JsonObject transformResults(JsonObject caliperResults) { return new JsonObject().add("name", extractSimpleName(caliperResults)) .add("details", extractEnvironment(caliperResults)) .add("measurements", extractMeasurements(caliperResults)); }
/** * Creates a new empty JsonObject. This is equivalent to creating a new JsonObject using the * constructor. * * @return a new empty JSON object */ public static JsonObject object() { return new JsonObject(); }
private static JsonObject extractMeasurement(JsonObject measurement) { JsonObject times = measurement.get("v").asObject() .get("measurementSetMap").asObject() .get("TIME").asObject(); return new JsonObject().add("variables", measurement.get("k").asObject().get("variables")) .add("units", times.get("unitNames")) .add("values", extractTimes(times.get("measurements").asArray())); }
private JsonObject toJson(Map<String, String> tags) { final JsonObject obj = new JsonObject(); for (Map.Entry<String, String> entry : tags.entrySet()) { obj.add(entry.getKey(), entry.getValue()); } return obj; }
/** * Constructs an empty BoxJSONObject. */ public BoxJsonObject() { createFromJson(new JsonObject()); }
/** * Creates a new metadata with the specified scope and template. * @param scope the scope of the metadata. * @param template the template of the metadata. */ public Metadata(String scope, String template) { JsonObject object = new JsonObject() .add("$scope", scope) .add("$template", template); this.values = object; }
/** * Assigns retention policy with givenID to the enterprise. * @param api the API connection to be used by the created assignment. * @param policyID id of the assigned retention policy. * @return info about created assignment. */ public static BoxRetentionPolicyAssignment.Info createAssignmentToEnterprise(BoxAPIConnection api, String policyID) { return createAssignment(api, policyID, new JsonObject().add("type", TYPE_ENTERPRISE), null); }
@Override protected String createStringRepresentation() { final com.eclipsesource.json.JsonObject minJsonObject = new com.eclipsesource.json.JsonObject(); fields.values().forEach(field -> minJsonObject.add(field.getKeyName(), JsonFactory.convert(field.getValue()))); return minJsonObject.toString(); }
protected JsonObject buildSubscriptionObject() { JsonObject subscriptionObject = new JsonObject(); subscriptionObject.add("channelType", "httpLongPoll"); subscriptionObject.add("template", "raw"); JsonArray interestedResources = new JsonArray(); this.resources.forEach(interestedResources::add); subscriptionObject.add("interestedResources", interestedResources); return subscriptionObject; }
private void sendImage(byte[] data, String imageName) throws ConnectionException, IOException { String id = Utils.uploadImage(data, Utils.ImageType.IMGT1, this); long ms = System.currentTimeMillis(); String content = "<URIObject type=\"Picture.1\" uri=\"https://api.asm.skype.com/v1/objects/%s\" url_thumbnail=\"https://api.asm.skype.com/v1/objects/%s/views/imgt1\">MyLegacy pish <a href=\"https://api.asm.skype.com/s/i?%s\">https://api.asm.skype.com/s/i?%s</a><Title/><Description/><OriginalName v=\"%s\"/><meta type=\"photo\" originalName=\"%s\"/></URIObject>"; content = String.format(content, id, id, id, id, imageName, imageName); JsonObject obj = new JsonObject(); obj.add("content", content); obj.add("messagetype", "RichText/UriObject"); obj.add("contenttype", "text"); obj.add("clientmessageid", String.valueOf(ms)); Endpoints.SEND_MESSAGE_URL.open(getClient(), getIdentity()).expect(201, "While sending message").post(obj); }
@Override public void sendContact(Contact contact) throws ConnectionException { long ms = System.currentTimeMillis(); JsonObject obj = new JsonObject(); obj.add("content", String.format("<contacts><c t=\"s\" s=\"%s\" f=\"%s\"/></contacts>", contact.getUsername(), contact.getDisplayName())); obj.add("messagetype", "RichText/Contacts"); obj.add("contenttype", "text"); obj.add("clientmessageid", String.valueOf(ms)); Endpoints.SEND_MESSAGE_URL.open(getClient(), getIdentity()).expect(201, "While sending message").post(obj); }
private BoxCollaboration.Info collaborate(JsonObject accessibleByField, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath) { JsonObject itemField = new JsonObject(); itemField.add("id", this.getID()); itemField.add("type", "file"); return BoxCollaboration.create(this.getAPI(), accessibleByField, itemField, role, notify, canViewPath); }
@Override public GroupChat joinChat(String id) throws ConnectionException, ChatNotFoundException, NoPermissionException { Validate.isTrue(id.startsWith("19:") && id.endsWith("@thread.skype"), "Invalid chat id"); JsonObject obj = new JsonObject(); obj.add("role", "User"); Endpoints.ADD_MEMBER_URL.open(this, id, getUsername()).on(403, (connection) -> { throw new NoPermissionException(); }).on(404, (connection) -> { throw new ChatNotFoundException(); }).expect(200, "While joining chat").put(obj); return (GroupChat) getOrLoadChat(id); }
@Override public void updated(RegistrationUpdate update, Registration updatedRegistration, Registration previousRegistration) { JsonObject value = new JsonObject(); value.add("regUpdate", RegistrationUpdateSerDes.jSerialize(update)); value.add("regUpdated", RegistrationSerDes.jSerialize(updatedRegistration)); try (Jedis j = pool.getResource()) { j.publish(UPDATE_EVENT, value.toString()); } }
@Override public void setRole(Participant.Role role) throws ConnectionException, NoPermissionException { if (!(getChat() instanceof GroupChat)) throw new NoPermissionException(); Endpoints.MODIFY_MEMBER_URL.open(getClient(), getChat().getIdentity(), getId()).on(400, (connection) -> { throw new NoPermissionException(); }).expect(200, "While updating role").put(new JsonObject().add("role", role.name().toLowerCase())); updateRole(role); }