-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
leshan-server-demo, current master, LwM2mNodeDeserializer.java IllegalStateException("This is not a JSON Primitive.") on opaque #799
Comments
I'm not sure to get you point. It seems you want to write an opaque value, right ? Currently to do that you need to send a payload like this : {"id":0,"value":"012ABC"} And you would like to be able to do something like this ? {"id":0,"value":["0","1","2","a","b","c"]} If,I'm right. Could you explain why ? |
I am not sending payload. GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeSerializer());
gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeDeserializer());
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
this.gson = gsonBuilder.create(); and then String response = this.gson.toJson(lwm2mObject); and then there is error
LwM2mNodeSerializer.java already creating char[] from OPAQUE type, I am just added decode what was missing. Code from LwM2mNodeSerializer.java ...
if (rsc.isMultiInstances()) {
JsonObject values = new JsonObject();
for (Entry<Integer, ?> entry : rsc.getValues().entrySet()) {
if (rsc.getType() == org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE) {
values.add(entry.getKey().toString(),
context.serialize(Hex.encodeHex((byte[]) entry.getValue())));
} else {
values.add(entry.getKey().toString(), context.serialize(entry.getValue()));
}
}
element.add("values", values);
} else {
if (rsc.getType() == org.eclipse.leshan.core.model.ResourceModel.Type.OPAQUE) {
element.add("value", context.serialize(Hex.encodeHex((byte[]) rsc.getValue())));
} else {
element.add("value", context.serialize(rsc.getValue()));
}
}
... So sequence is like this.. I serialize Lwm2mObject where is opaque values and when I want to deserialize this object, then I get IllegalStateException. char[] is not a JsonPrimitive. |
OK I get you point. You just want to make LwM2mNodeDeserializer and LwM2mNodeSerializer consistent. As the rest API :
I'm not sure to see why this is needed ? but we can add it if this helps. |
Oh, ok, I am using this to store / cache and later retrieve objects. Do stuff, check previous values etc. |
#806 will now encode Opaque value as an hexa string. This is more consistent. |
Leshan-server-demo, current master, LwM2mNodeDeserializer.java IllegalStateException("This is not a JSON Primitive.") on opaque value
Deserializing opaque values throws IllegalStateException("This is not a JSON Primitive.").
As far as I know, this works.
Added function
and changed code from
to
If you have time to check and upgrade leshan server demo deserializer it would be nice.
This is only info for others, you can close this isue ;)
The text was updated successfully, but these errors were encountered: