Skip to content

Commit

Permalink
fix OPAQUE value serialization in leshan-standalone.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Mar 11, 2015
1 parent 96c7068 commit aa02658
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

import java.lang.reflect.Type;

import javax.xml.bind.DatatypeConverter;

import org.eclipse.leshan.core.node.LwM2mNode;
import org.eclipse.leshan.core.node.LwM2mObject;
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.node.Value.DataType;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
Expand All @@ -44,15 +47,23 @@ public JsonElement serialize(LwM2mNode src, Type typeOfSrc, JsonSerializationCon
if (rsc.isMultiInstances()) {
Object[] values = new Object[rsc.getValues().length];
for (int i = 0; i < rsc.getValues().length; i++) {
values[i] = rsc.getValues()[i].value;
if (rsc.getValue().type == DataType.OPAQUE) {
values[i] = DatatypeConverter.printHexBinary((byte[]) rsc.getValue().value);
} else {
values[i] = rsc.getValues()[i].value;
}
}
element.add("values", context.serialize(values));
} else {
element.add("value", context.serialize(rsc.getValue().value));
if (rsc.getValue().type == DataType.OPAQUE) {
element.add("value",
context.serialize(DatatypeConverter.printHexBinary((byte[]) rsc.getValue().value)));
} else {
element.add("value", context.serialize(rsc.getValue().value));
}
}
}

return element;
}

}

0 comments on commit aa02658

Please sign in to comment.