use of com.eclipsesource.json.JsonArray in project hazelcast by hazelcast.
the class LocalOperationStatsImpl method toJson.
@Override
public JsonObject toJson() {
JsonObject root = new JsonObject();
root.add("maxVisibleSlowOperationCount", maxVisibleSlowOperationCount);
JsonArray slowOperationArray = new JsonArray();
int logCount = 0;
for (SlowOperationDTO slowOperation : slowOperations) {
if (logCount++ < maxVisibleSlowOperationCount) {
slowOperationArray.add(slowOperation.toJson());
}
}
root.add("slowOperations", slowOperationArray);
root.add("creationTime", creationTime);
return root;
}
use of com.eclipsesource.json.JsonArray in project leshan by eclipse.
the class JsonRootObjectSerDes method jSerialize.
@Override
public JsonObject jSerialize(JsonRootObject jro) {
JsonObject o = new JsonObject();
if (jro.getBaseName() != null)
o.add("bn", jro.getBaseName());
JsonArray ja = serDes.jSerialize(jro.getResourceList());
if (ja != null)
o.add("e", ja);
if (jro.getBaseTime() != null)
o.add("bt", jro.getBaseTime());
return o;
}
use of com.eclipsesource.json.JsonArray in project leshan by eclipse.
the class ObjectModelSerDes method jSerialize.
@Override
public JsonObject jSerialize(ObjectModel m) {
final JsonObject o = Json.object();
o.add("name", m.name);
o.add("id", m.id);
o.add("instancetype", m.multiple ? "multiple" : "single");
o.add("mandatory", m.mandatory);
if (!ObjectModel.DEFAULT_VERSION.equals(m.version))
o.add("version", m.version);
o.add("description", m.description);
// sort resources value
List<ResourceModel> resourceSpecs = new ArrayList<>(m.resources.values());
Collections.sort(resourceSpecs, new Comparator<ResourceModel>() {
@Override
public int compare(ResourceModel r1, ResourceModel r2) {
return r1.id - r2.id;
}
});
JsonArray rs = new JsonArray();
for (ResourceModel rm : resourceSpecs) {
rs.add(resourceModelSerDes.jSerialize(rm));
}
o.add("resourcedefs", rs);
return o;
}
use of com.eclipsesource.json.JsonArray in project leshan by eclipse.
the class RegistrationUpdateSerDes method jSerialize.
public static JsonObject jSerialize(RegistrationUpdate u) {
JsonObject o = Json.object();
// mandatory fields
o.add("regId", u.getRegistrationId());
o.add("identity", IdentitySerDes.serialize(u.getIdentity()));
// optional fields
if (u.getLifeTimeInSec() != null)
o.add("lt", u.getLifeTimeInSec());
if (u.getSmsNumber() != null)
o.add("sms", u.getSmsNumber());
if (u.getBindingMode() != null)
o.add("bnd", u.getBindingMode().name());
if (u.getObjectLinks() != null) {
JsonArray links = new JsonArray();
for (Link l : u.getObjectLinks()) {
JsonObject ol = Json.object();
ol.add("url", l.getUrl());
JsonObject at = Json.object();
for (Map.Entry<String, Object> e : l.getAttributes().entrySet()) {
if (e.getValue() == null) {
at.add(e.getKey(), Json.NULL);
} else if (e.getValue() instanceof Integer) {
at.add(e.getKey(), (int) e.getValue());
} else {
at.add(e.getKey(), e.getValue().toString());
}
}
ol.add("at", at);
links.add(ol);
}
o.add("objLink", links);
}
if (u.getAdditionalAttributes() != null) {
JsonObject addAttr = Json.object();
for (Map.Entry<String, String> e : u.getAdditionalAttributes().entrySet()) {
addAttr.add(e.getKey(), e.getValue());
}
o.add("addAttr", addAttr);
}
return o;
}
use of com.eclipsesource.json.JsonArray in project leshan by eclipse.
the class RegistrationUpdateSerDes method deserialize.
public static RegistrationUpdate deserialize(byte[] data) throws UnknownHostException {
JsonObject v = (JsonObject) Json.parse(new String(data));
// mandatory fields
String regId = v.getString("regId", null);
Identity identity = IdentitySerDes.deserialize(v.get("identity").asObject());
// optional fields
BindingMode b = null;
if (v.get("bnd") != null) {
b = BindingMode.valueOf(v.getString("bnd", null));
}
Long lifetime = null;
if (v.get("lt") != null) {
lifetime = v.getLong("lt", 0);
}
String sms = null;
if (v.get("sms") != null) {
sms = v.getString("sms", "");
}
// parse object link
JsonArray links = (JsonArray) v.get("objLink");
Link[] linkObjs = null;
if (links != null) {
linkObjs = new Link[links.size()];
for (int i = 0; i < links.size(); i++) {
JsonObject ol = (JsonObject) links.get(i);
Map<String, Object> attMap = new HashMap<>();
JsonObject att = (JsonObject) ol.get("at");
for (String k : att.names()) {
JsonValue jsonValue = att.get(k);
if (jsonValue.isNull()) {
attMap.put(k, null);
} else if (jsonValue.isNumber()) {
attMap.put(k, jsonValue.asInt());
} else {
attMap.put(k, jsonValue.asString());
}
}
Link o = new Link(ol.getString("url", null), attMap);
linkObjs[i] = o;
}
}
Map<String, String> addAttr = new HashMap<>();
JsonObject o = (JsonObject) v.get("addAttr");
for (String k : o.names()) {
addAttr.put(k, o.getString(k, ""));
}
return new RegistrationUpdate(regId, identity, lifetime, sms, b, linkObjs, addAttr);
}
Aggregations