Search in sources :

Example 41 with JsonValue

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();
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) Date(java.util.Date) JsonArray(com.eclipsesource.json.JsonArray) Registration(org.eclipse.leshan.server.registration.Registration) JsonObject(com.eclipsesource.json.JsonObject) Link(org.eclipse.leshan.Link)

Example 42 with JsonValue

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);
}
Also used : RawData(org.eclipse.californium.elements.RawData) EndpointContext(org.eclipse.californium.elements.EndpointContext) HashMap(java.util.HashMap) Request(org.eclipse.californium.core.coap.Request) JsonValue(com.eclipsesource.json.JsonValue) Observation(org.eclipse.californium.core.observe.Observation) JsonObject(com.eclipsesource.json.JsonObject)

Example 43 with JsonValue

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;
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Aggregations

JsonValue (com.eclipsesource.json.JsonValue)43 JsonObject (com.eclipsesource.json.JsonObject)19 JsonArray (com.eclipsesource.json.JsonArray)12 HashMap (java.util.HashMap)6 ParseException (com.eclipsesource.json.ParseException)4 IOException (java.io.IOException)4 InetSocketAddress (java.net.InetSocketAddress)3 Member (com.eclipsesource.json.JsonObject.Member)2 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)2 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 PublicKey (java.security.PublicKey)2 X509EncodedKeySpec (java.security.spec.X509EncodedKeySpec)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Map (java.util.Map)2 EndpointContext (org.eclipse.californium.elements.EndpointContext)2 Link (org.eclipse.leshan.Link)2