Skip to content

Commit

Permalink
Add values ID deserialization of multi-instance resource in server-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Oct 4, 2017
1 parent cd08129 commit 08594ab
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.eclipse.leshan.core.node.LwM2mMultipleResource;
import org.eclipse.leshan.core.node.LwM2mNode;
Expand Down Expand Up @@ -81,14 +82,11 @@ public LwM2mNode deserialize(JsonElement json, Type typeOfT, JsonDeserialization
} else if (object.has("values")) {
// multi-instances resource
Map<Integer, Object> values = new HashMap<>();
// TODO handle id for multiple resource
int i = 0;
org.eclipse.leshan.core.model.ResourceModel.Type expectedType = null;
for (JsonElement val : object.get("values").getAsJsonArray()) {
JsonPrimitive pval = val.getAsJsonPrimitive();
for (Entry<String, JsonElement> entry : object.get("values").getAsJsonObject().entrySet()) {
JsonPrimitive pval = entry.getValue().getAsJsonPrimitive();
expectedType = getTypeFor(pval);
values.put(i, deserializeValue(pval, expectedType));
i++;
values.put(Integer.valueOf(entry.getKey()), deserializeValue(pval, expectedType));
}
// use string by default;
if (expectedType == null)
Expand Down

0 comments on commit 08594ab

Please sign in to comment.