Пример #1
0
 private org.eclipse.leshan.core.model.ResourceModel.Type getTypeFor(JsonPrimitive val) {
   if (val.isBoolean()) return org.eclipse.leshan.core.model.ResourceModel.Type.BOOLEAN;
   if (val.isString()) return org.eclipse.leshan.core.model.ResourceModel.Type.STRING;
   if (val.isNumber()) {
     if (val.getAsDouble() == (long) val.getAsLong()) {
       return org.eclipse.leshan.core.model.ResourceModel.Type.BOOLEAN;
     } else {
       return org.eclipse.leshan.core.model.ResourceModel.Type.BOOLEAN;
     }
   }
   // use string as default value
   return org.eclipse.leshan.core.model.ResourceModel.Type.STRING;
 }
Пример #2
0
 private Object deserializeValue(
     JsonPrimitive val, org.eclipse.leshan.core.model.ResourceModel.Type expectedType) {
   switch (expectedType) {
     case BOOLEAN:
       return val.getAsBoolean();
     case STRING:
       return val.getAsString();
     case INTEGER:
       return val.getAsLong();
     case FLOAT:
       return val.getAsDouble();
     case TIME:
     case OPAQUE:
     default:
       // TODO we need to better handle this.
       return val.getAsString();
   }
 }