use of org.eclipse.leshan.core.request.DeleteRequest in project leshan by eclipse.
the class DownlinkRequestSerDes method jSerialize.
public static JsonObject jSerialize(DownlinkRequest<?> r) {
final JsonObject o = Json.object();
o.add("path", r.getPath().toString());
r.accept(new DownLinkRequestVisitorAdapter() {
@Override
public void visit(ObserveRequest request) {
o.add("kind", "observe");
if (request.getContentFormat() != null)
o.add("contentFormat", request.getContentFormat().getCode());
}
@Override
public void visit(DeleteRequest request) {
o.add("kind", "delete");
}
@Override
public void visit(DiscoverRequest request) {
o.add("kind", "discover");
}
@Override
public void visit(CreateRequest request) {
o.add("kind", "create");
o.add("contentFormat", request.getContentFormat().getCode());
if (request.getInstanceId() != null)
o.add("instanceId", request.getInstanceId());
JsonArray resources = new JsonArray();
for (LwM2mResource resource : request.getResources()) {
resources.add(LwM2mNodeSerDes.jSerialize(resource));
}
o.add("resources", resources);
}
@Override
public void visit(ExecuteRequest request) {
o.add("kind", "execute");
o.add("parameters", request.getParameters());
}
@Override
public void visit(WriteAttributesRequest request) {
o.add("kind", "writeAttributes");
o.add("observeSpec", request.getObserveSpec().toString());
}
@Override
public void visit(WriteRequest request) {
o.add("kind", "write");
o.add("contentFormat", request.getContentFormat().getCode());
o.add("mode", request.isPartialUpdateRequest() ? "UPDATE" : "REPLACE");
o.add("node", LwM2mNodeSerDes.jSerialize(request.getNode()));
}
@Override
public void visit(ReadRequest request) {
o.add("kind", "read");
if (request.getContentFormat() != null)
o.add("contentFormat", request.getContentFormat().getCode());
}
});
return o;
}
Aggregations