case ENUM :
return new StringValue(((Enum)object).name());
case CLASS :
return new StringValue(((Class)object).getName());
case ARRAY_BOOLEAN : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new BooleanValue(Array.getBoolean(object, i)));
}
return jsonArray;
}
case ARRAY_BYTE : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new LongValue(Array.getByte(object, i)));
}
return jsonArray;
}
case ARRAY_SHORT : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new LongValue(Array.getShort(object, i)));
}
return jsonArray;
}
case ARRAY_INT : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new LongValue(Array.getInt(object, i)));
}
return jsonArray;
}
case ARRAY_LONG : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new LongValue(Array.getLong(object, i)));
}
return jsonArray;
}
case ARRAY_FLOAT : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new DoubleValue(Array.getFloat(object, i)));
}
return jsonArray;
}
case ARRAY_DOUBLE : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new DoubleValue(Array.getDouble(object, i)));
}
return jsonArray;
}
case ARRAY_CHAR : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new StringValue(Character.toString(Array.getChar(object, i))));
}
return jsonArray;
}
case ARRAY_STRING : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
jsonArray.addElement(new StringValue((String)Array.get(object, i)));
}
return jsonArray;
}
case ARRAY_OBJECT : {
JsonValue jsonArray = new ArrayValue();
int length = Array.getLength(object);
for (int i = 0; i < length; i++)
{
Object el = Array.get(object, i);
if (JsonUtils.getType(el) != null)
{
jsonArray.addElement(createJsonValue(el));
}
else
{
jsonArray.addElement(createJsonObject(el));
}
}
return jsonArray;
}
case COLLECTION : {
JsonValue jsonArray = new ArrayValue();
List<Object> list = new ArrayList<Object>((Collection<?>)object);
for (Object o : list)
{
if (JsonUtils.getType(o) != null)
{
jsonArray.addElement(createJsonValue(o));
}
else
{
jsonArray.addElement(createJsonObject(o));
}
}
return jsonArray;
}
case MAP :
JsonValue jsonObject = new ObjectValue();
Map<String, Object> map = new HashMap<String, Object>((Map<String, Object>)object);
Set<String> keys = map.keySet();
for (String k : keys)
{
Object o = map.get(k);
if (JsonUtils.getType(o) != null)
{
jsonObject.addElement(k, createJsonValue(o));
}
else
{
jsonObject.addElement(k, createJsonObject(o));
}
}
return jsonObject;
default :
// Must not be here!