Let say there is deepstream client and JsonElement object jsonObj, then update record with jsonObj.
Record record = client.record.getRecord(recordName);
record.set(jsonObj);
Please refer to following code that copied from Record.java, as we can see, record.set(jsonObj) will invoke inner private method set(String path, Object value, boolean force), In runtime the last else condition will be matched. "element = this.gson.toJsonTree(value)" will construct JsonWriter, and write value into JsonWriter, then get JsonElement from JsonWriter. But the value is already JsonElement.
Following code is copied from Record.java
@ObjectiveCName("set:")
public Record set(JsonElement value) throws DeepstreamRecordDestroyedException {
return this.set((String)null, value, false);
}
@ObjectiveCName("set:value:force:")
private Record set(String path, Object value, boolean force) throws DeepstreamRecordDestroyedException {
this.throwExceptionIfDestroyed("set");
Object element;
if (value instanceof String) {
element = new JsonPrimitive((String)value);
} else if (value instanceof Number) {
element = new JsonPrimitive((Number)value);
} else if (value instanceof Boolean) {
element = new JsonPrimitive((Boolean)value);
} else {
element = this.gson.toJsonTree(value);
}
JsonElement object = this.path.get(path);
if (!force) {
if (object != null && object.equals(value)) {
return this;
}
if (path == null && this.data.equals(value)) {
return this;
}
}
Map<String, JsonElement> oldValues = this.beginChange();
this.path.set(path, (JsonElement)element);
this.data = this.path.getCoreElement();
this.sendUpdate(path, value);
this.completeChange(oldValues);
return this;
}
Let say there is deepstream client and JsonElement object jsonObj, then update record with jsonObj.
Please refer to following code that copied from Record.java, as we can see, record.set(jsonObj) will invoke inner private method set(String path, Object value, boolean force), In runtime the last else condition will be matched. "element = this.gson.toJsonTree(value)" will construct JsonWriter, and write value into JsonWriter, then get JsonElement from JsonWriter. But the value is already JsonElement.