// Character isn't a java.lang.Number
|| value instanceof Character
// Timestamp includes nanoseconds, and has a special String representation that is parseable
|| value instanceof Timestamp) {
return new JSONString(value.toString());
}
else if (value instanceof Boolean) {
return JSONBoolean.getInstance((Boolean) value);
}
else if (value instanceof Number) {
return new JSONNumber(((Number) value).doubleValue());
}
else if (value instanceof Enum) {
return new JSONString(((Enum<?>) value).name());
}
else if (value instanceof Date) { // covers java.sql.[Date,Time,Timestamp]
return new JSONString(String.valueOf(((Date) value).getTime()));
}
else if (value instanceof byte[]) {
byte[] v = (byte[]) value;
return new JSONString(Base64Util.encode(v, 0, v.length));
}
else if (value instanceof Byte[]) {
Byte[] v = (Byte[]) value;
return new JSONString(Base64Util.encode(v, 0, v.length));
}
else if (value instanceof char[]) {
return new JSONString(String.copyValueOf(((char[]) value)));
}
else if (value instanceof Character[]) {
Character[] v = (Character[]) value;
StringBuilder sb = new StringBuilder(v.length);
for (Character c : v) {
sb.append((char) c);
}
return new JSONString(sb.toString());
}
else {
throw new RuntimeException("I don't know how JSONify " + value + " (" + value.getClass() + ")");
}
}