remove fastjson dependency

This commit is contained in:
wenshao
2012-08-21 15:46:10 +08:00
parent a530c906ae
commit 7cea73b2c1
9 changed files with 94 additions and 40 deletions
@@ -207,6 +207,7 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
@SuppressWarnings("unchecked")
public static Set<DruidDataSource> getDruidDataSourceInstances() {
getInstances();
return dataSources.keySet();
}
@@ -5,6 +5,9 @@ import java.util.Collection;
import java.util.Date;
import java.util.Map;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData;
import com.alibaba.druid.util.IOUtils;
public class JSONWriter {
@@ -24,16 +27,6 @@ public class JSONWriter {
return;
}
if (o instanceof Map) {
writeMap((Map) o);
return;
}
if (o instanceof Collection) {
writeArray((Collection) o);
return;
}
if (o instanceof String) {
writeString((String) o);
return;
@@ -54,6 +47,11 @@ public class JSONWriter {
return;
}
if (o instanceof Collection) {
writeArray((Collection) o);
return;
}
if (o instanceof Throwable) {
writeError((Throwable) o);
return;
@@ -85,6 +83,21 @@ public class JSONWriter {
return;
}
if (o instanceof TabularData) {
writeTabularData((TabularData) o);
return;
}
if (o instanceof CompositeData) {
writeCompositeData((CompositeData) o);
return;
}
if (o instanceof Map) {
writeMap((Map) o);
return;
}
throw new IllegalArgumentException("not support type : " + o.getClass());
}
@@ -169,6 +182,50 @@ public class JSONWriter {
write('"');
}
public void writeTabularData(TabularData tabularData) {
if (tabularData == null) {
write("null");
return;
}
int entryIndex = 0;
write('[');
for (Object item : tabularData.values()) {
if (entryIndex != 0) {
write(',');
}
CompositeData row = (CompositeData) item;
writeCompositeData(row);
entryIndex++;
}
write(']');
}
public void writeCompositeData(CompositeData compositeData) {
if (compositeData == null) {
write("null");
return;
}
int entryIndex = 0;
write('{');
for (Object key : compositeData.getCompositeType().keySet()) {
if (entryIndex != 0) {
write(',');
}
writeString((String) key);
write(':');
Object value = compositeData.get((String) key);
writeObject(value);
entryIndex++;
}
write('}');
}
public void writeMap(Map<String, Object> map) {
if (map == null) {
write("null");