use of com.eclipsesource.json.JsonValue in project leshan by eclipse.
the class RegistrationSerDes method deserialize.
public static Registration deserialize(JsonObject jObj) {
Registration.Builder b = new Registration.Builder(jObj.getString("regId", null), jObj.getString("ep", null), IdentitySerDes.deserialize(jObj.get("identity").asObject()), new InetSocketAddress(jObj.getString("regAddr", null), jObj.getInt("regPort", 0)));
b.bindingMode(BindingMode.valueOf(jObj.getString("bnd", null)));
b.lastUpdate(new Date(jObj.getLong("lastUp", 0)));
b.lifeTimeInSec(jObj.getLong("lt", 0));
b.lwM2mVersion(jObj.getString("ver", "1.0"));
b.registrationDate(new Date(jObj.getLong("regDate", 0)));
if (jObj.get("sms") != null) {
b.smsNumber(jObj.getString("sms", ""));
}
JsonArray links = (JsonArray) jObj.get("objLink");
Link[] 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;
}
b.objectLinks(linkObjs);
Map<String, String> addAttr = new HashMap<>();
JsonObject o = (JsonObject) jObj.get("addAttr");
for (String k : o.names()) {
addAttr.put(k, o.getString(k, ""));
}
b.additionalRegistrationAttributes(addAttr);
return b.build();
}
use of com.eclipsesource.json.JsonValue in project leshan by eclipse.
the class ObservationSerDes method deserialize.
public static Observation deserialize(byte[] data) {
JsonObject v = (JsonObject) Json.parse(new String(data));
EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject());
byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray());
RawData rawData = RawData.outbound(req, endpointContext, null, false);
Request request = (Request) parser.parseMessage(rawData);
request.setDestinationContext(endpointContext);
JsonValue ctxValue = v.get("context");
if (ctxValue != null) {
Map<String, String> context = new HashMap<>();
JsonObject ctxObject = (JsonObject) ctxValue;
for (String name : ctxObject.names()) {
context.put(name, ctxObject.getString(name, null));
}
request.setUserContext(context);
}
return new Observation(request, endpointContext);
}
use of com.eclipsesource.json.JsonValue in project wildfly-swarm by wildfly-swarm.
the class FractionListParser method getFractionDescriptor.
private FractionDescriptor getFractionDescriptor(JsonObject fraction) {
String groupId = toString(fraction.get("groupId"));
String artifactId = toString(fraction.get("artifactId"));
String key = groupId + ":" + artifactId;
FractionDescriptor descriptor = descriptors.get(key);
if (descriptor == null) {
String version = toString(fraction.get("version"));
String name = toString(fraction.get("name"));
String description = toString(fraction.get("description"));
String tags = toString(fraction.get("tags"));
boolean internal = toBoolean(fraction.get("internal"));
JsonValue stabilityIndexJson = fraction.get("stabilityIndex");
int stabilityIndex = stabilityIndexJson == null || stabilityIndexJson.isNull() ? FractionStability.UNSTABLE.ordinal() : stabilityIndexJson.asInt();
FractionStability stability;
if (stabilityIndex < 0 || stabilityIndex >= FractionStability.values().length) {
stability = FractionStability.UNSTABLE;
} else {
stability = FractionStability.values()[stabilityIndex];
}
descriptor = new FractionDescriptor(groupId, artifactId, version, name, description, tags, internal, stability);
descriptors.put(key, descriptor);
}
return descriptor;
}
Aggregations