Search in sources :

Example 21 with WriteResponse

use of org.eclipse.leshan.core.response.WriteResponse in project leshan by eclipse.

the class ResponseSerDes method deserialize.

public static LwM2mResponse deserialize(JsonObject o) {
    String sCode = o.getString("code", null);
    if (sCode == null)
        throw new IllegalStateException("Invalid response missing code attribute");
    ResponseCode code = ResponseCode.fromName(sCode);
    String errorMessage = o.getString("errorMessage", null);
    String kind = o.getString("kind", null);
    switch(kind) {
        case "observe":
            {
                // TODO ser Observation
                LwM2mNode content = LwM2mNodeSerDes.deserialize((JsonObject) o.get("content"));
                return new ObserveResponse(code, content, null, null, errorMessage);
            }
        case "delete":
            return new DeleteResponse(code, errorMessage);
        case "discover":
            String objectLinks = o.getString("objectLinks", "");
            return new DiscoverResponse(code, Link.parse(objectLinks.getBytes()), errorMessage);
        case "create":
            {
                String location = o.getString("location", null);
                return new CreateResponse(code, location, errorMessage);
            }
        case "execute":
            return new ExecuteResponse(code, errorMessage);
        case "writeAttributes":
            {
                return new WriteAttributesResponse(code, errorMessage);
            }
        case "write":
            {
                return new WriteResponse(code, errorMessage);
            }
        case "read":
            {
                LwM2mNode content = LwM2mNodeSerDes.deserialize((JsonObject) o.get("content"));
                return new ReadResponse(code, content, errorMessage);
            }
        default:
            throw new IllegalStateException("Invalid response missing kind attribute");
    }
}
Also used : ResponseCode(org.eclipse.leshan.ResponseCode) CreateResponse(org.eclipse.leshan.core.response.CreateResponse) WriteResponse(org.eclipse.leshan.core.response.WriteResponse) JsonObject(com.eclipsesource.json.JsonObject) WriteAttributesResponse(org.eclipse.leshan.core.response.WriteAttributesResponse) DiscoverResponse(org.eclipse.leshan.core.response.DiscoverResponse) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) LwM2mNode(org.eclipse.leshan.core.node.LwM2mNode) ObserveResponse(org.eclipse.leshan.core.response.ObserveResponse) DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) ReadResponse(org.eclipse.leshan.core.response.ReadResponse)

Aggregations

WriteResponse (org.eclipse.leshan.core.response.WriteResponse)21 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)19 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)14 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)12 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)10 Test (org.junit.Test)8 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)4 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)4 ObjectLink (org.eclipse.leshan.core.node.ObjectLink)3 ContentFormat (org.eclipse.leshan.core.request.ContentFormat)3 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)3 ExecuteResponse (org.eclipse.leshan.core.response.ExecuteResponse)3 WriteAttributesResponse (org.eclipse.leshan.core.response.WriteAttributesResponse)3 JsonObject (com.eclipsesource.json.JsonObject)2 ResourceUtil.extractServerIdentity (org.eclipse.leshan.client.californium.impl.ResourceUtil.extractServerIdentity)2 ServerIdentity (org.eclipse.leshan.client.request.ServerIdentity)2 LwM2mModel (org.eclipse.leshan.core.model.LwM2mModel)2 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)2 LwM2mSingleResource (org.eclipse.leshan.core.node.LwM2mSingleResource)2 CodecException (org.eclipse.leshan.core.node.codec.CodecException)2