return (JSONValue) value;
} else if (value instanceof String[]) {
String[] array = (String[]) value;
JSONArray jsonArray = new JSONArray();
for (int i = 0; i < array.length; ++i) {
jsonArray.set(i, new JSONString(array[i]));
}
return jsonArray;
} else if (value instanceof String) {
return new JSONString((String) value);
} else if (value instanceof Boolean) {
return JSONBoolean.getInstance((Boolean) value);
} else if (value instanceof Byte) {
return new JSONNumber((Byte) value);
} else if (value instanceof Character) {
return new JSONString(String.valueOf(value));
} else if (value instanceof Object[] && type == null) {
// Non-legacy arrays handed by generated serializer
return encodeLegacyObjectArray((Object[]) value, connection);
} else if (value instanceof Enum) {
return encodeEnum((Enum<?>) value, connection);
} else if (value instanceof Map) {
return encodeMap((Map) value, type, connection);
} else if (value instanceof Connector) {
Connector connector = (Connector) value;
return new JSONString(connector.getConnectorId());
} else if (value instanceof Collection) {
return encodeCollection((Collection) value, type, connection);
} else if (value instanceof UidlValue) {
return encodeVariableChange((UidlValue) value, connection);
} else {
// First see if there's a custom serializer
JSONSerializer<Object> serializer = null;
if (type != null) {
serializer = (JSONSerializer<Object>) type.findSerializer();
if (serializer != null) {
return serializer.serialize(value, connection);
}
}
String transportType = getTransportType(value);
if (transportType != null) {
// Send the string value for remaining legacy types
return new JSONString(String.valueOf(value));
} else if (type != null) {
// And finally try using bean serialization logic
try {
JsArrayObject<Property> properties = type
.getPropertiesAsArray();