use of com.eclipsesource.json.JsonArray in project leshan by eclipse.
the class LwM2mNodeSerDes method deserialize.
public static LwM2mNode deserialize(JsonObject o) {
String kind = o.getString("kind", null);
int id = o.getInt("id", LwM2mObjectInstance.UNDEFINED);
switch(kind) {
case "object":
{
Collection<LwM2mObjectInstance> instances = new ArrayList<>();
JsonArray jInstances = (JsonArray) o.get("instances");
for (JsonValue jInstance : jInstances) {
LwM2mObjectInstance instance = (LwM2mObjectInstance) deserialize((JsonObject) jInstance);
instances.add(instance);
}
return new LwM2mObject(id, instances);
}
case "instance":
{
Collection<LwM2mResource> resources = new ArrayList<>();
JsonObject jResources = (JsonObject) o.get("resources");
for (Member jResource : jResources) {
LwM2mResource resource = (LwM2mResource) deserialize((JsonObject) jResource.getValue());
resources.add(resource);
}
return new LwM2mObjectInstance(id, resources);
}
case "singleResource":
{
String jType = o.getString("type", null);
if (jType == null)
throw new IllegalStateException("Invalid LwM2mNode missing type attribute");
Type type = Enum.valueOf(Type.class, jType);
Object value = ValueSerDes.deserialize(o.get("value"), type);
return LwM2mSingleResource.newResource(id, value, type);
}
case "multipleResource":
{
String jType = o.getString("type", null);
if (jType == null)
throw new IllegalStateException("Invalid LwM2mNode missing type attribute");
Type type = Enum.valueOf(Type.class, jType);
Map<Integer, Object> values = new HashMap<>();
JsonObject jValues = (JsonObject) o.get("values");
for (Member jValue : jValues) {
Integer valueId = Integer.valueOf(jValue.getName());
Object value = ValueSerDes.deserialize(jValue.getValue(), type);
values.put(valueId, value);
}
return LwM2mMultipleResource.newResource(id, values, type);
}
default:
throw new IllegalStateException("Invalid LwM2mNode missing kind attribute");
}
}
use of com.eclipsesource.json.JsonArray in project leshan by eclipse.
the class DownlinkRequestSerDes method deserialize.
public static DownlinkRequest<?> deserialize(JsonObject o) {
String kind = o.getString("kind", null);
String path = o.getString("path", null);
switch(kind) {
case "observe":
{
int format = o.getInt("contentFormat", ContentFormat.TLV.getCode());
return new ObserveRequest(ContentFormat.fromCode(format), path);
}
case "delete":
return new DeleteRequest(path);
case "discover":
return new DiscoverRequest(path);
case "create":
{
int format = o.getInt("contentFormat", ContentFormat.TLV.getCode());
int instanceId = o.getInt("instanceId", LwM2mObjectInstance.UNDEFINED);
Collection<LwM2mResource> resources = new ArrayList<>();
JsonArray jResources = (JsonArray) o.get("resources");
for (JsonValue jResource : jResources) {
LwM2mResource resource = (LwM2mResource) LwM2mNodeSerDes.deserialize((JsonObject) jResource);
resources.add(resource);
}
return new CreateRequest(ContentFormat.fromCode(format), path, new LwM2mObjectInstance(instanceId, resources));
}
case "execute":
String parameters = o.getString("parameters", null);
return new ExecuteRequest(path, parameters);
case "writeAttributes":
{
String observeSpec = o.getString("observeSpec", null);
return new WriteAttributesRequest(path, ObserveSpec.parse(observeSpec));
}
case "write":
{
int format = o.getInt("contentFormat", ContentFormat.TLV.getCode());
Mode mode = o.getString("mode", "REPLACE").equals("REPLACE") ? Mode.REPLACE : Mode.UPDATE;
LwM2mNode node = LwM2mNodeSerDes.deserialize((JsonObject) o.get("node"));
return new WriteRequest(mode, ContentFormat.fromCode(format), path, node);
}
case "read":
{
int format = o.getInt("contentFormat", ContentFormat.TLV.getCode());
return new ReadRequest(ContentFormat.fromCode(format), path);
}
default:
throw new IllegalStateException("Invalid request missing kind attribute");
}
}
use of com.eclipsesource.json.JsonArray in project zencash-swing-wallet-ui by ZencashOfficial.
the class ZCashClientCaller method getWalletAllPublicAddresses.
// ./zcash-cli listreceivedbyaddress 0 true
public synchronized String[] getWalletAllPublicAddresses() throws WalletCallException, IOException, InterruptedException {
JsonArray jsonReceivedOutputs = executeCommandAndGetJsonArray("listreceivedbyaddress", "0", "true");
Set<String> addresses = new HashSet<>();
for (int i = 0; i < jsonReceivedOutputs.size(); i++) {
JsonObject outp = jsonReceivedOutputs.get(i).asObject();
addresses.add(outp.getString("address", "ERROR!"));
}
return addresses.toArray(new String[0]);
}
use of com.eclipsesource.json.JsonArray in project zencash-swing-wallet-ui by ZencashOfficial.
the class ZCashClientCaller method getWalletPublicTransactions.
public synchronized String[][] getWalletPublicTransactions() throws WalletCallException, IOException, InterruptedException {
String notListed = "\u26D4";
OS_TYPE os = OSUtil.getOSType();
if (os == OS_TYPE.WINDOWS) {
notListed = " \u25B6";
}
JsonArray jsonTransactions = executeCommandAndGetJsonArray("listtransactions", wrapStringParameter(""), "300");
String[][] strTransactions = new String[jsonTransactions.size()][];
for (int i = 0; i < jsonTransactions.size(); i++) {
strTransactions[i] = new String[7];
JsonObject trans = jsonTransactions.get(i).asObject();
// Needs to be the same as in getWalletZReceivedTransactions()
// TODO: some day refactor to use object containers
strTransactions[i][0] = "\u2606T (Public)";
strTransactions[i][1] = trans.getString("category", "ERROR!");
strTransactions[i][2] = trans.get("confirmations").toString();
strTransactions[i][3] = trans.get("amount").toString();
strTransactions[i][4] = trans.get("time").toString();
strTransactions[i][5] = trans.getString("address", notListed + " (Z Address not listed by wallet!)");
strTransactions[i][6] = trans.get("txid").toString();
}
return strTransactions;
}
use of com.eclipsesource.json.JsonArray in project zencash-swing-wallet-ui by ZencashOfficial.
the class ZCashClientCaller method getTransactionMessagingDataForZaddress.
public synchronized JsonObject[] getTransactionMessagingDataForZaddress(String ZAddress) throws WalletCallException, IOException, InterruptedException {
JsonArray jsonTransactions = executeCommandAndGetJsonArray("z_listreceivedbyaddress", wrapStringParameter(ZAddress), "0");
List<JsonObject> transactions = new ArrayList<JsonObject>();
for (int i = 0; i < jsonTransactions.size(); i++) {
JsonObject trans = jsonTransactions.get(i).asObject();
transactions.add(trans);
}
return transactions.toArray(new JsonObject[0]);
}
Aggregations