fixed compatible with JDK 5

This commit is contained in:
wenshao
2016-08-30 13:23:00 +08:00
parent 5a5234f2bc
commit 5e9ab06e8f
+11 -2
View File
@@ -16,6 +16,7 @@
package com.alibaba.fastjson;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.lang.reflect.Array;
import java.lang.reflect.Type;
@@ -112,7 +113,11 @@ public abstract class JSON implements JSONStreamAware, JSONAware {
}
public static final Object parse(byte[] input, Feature... features) {
return parseObject(new String(input, Charset.forName("UTF-8")), features);
try {
return parseObject(new String(input, "UTF-8"), features);
} catch (UnsupportedEncodingException e) {
throw new JSONException("UTF-8 not support");
}
}
public static final Object parse(String text, Feature... features) {
@@ -224,7 +229,11 @@ public abstract class JSON implements JSONStreamAware, JSONAware {
@SuppressWarnings("unchecked")
public static final <T> T parseObject(byte[] input, Type clazz, Feature... features) {
return (T) parseObject(new String(input, Charset.forName("UTF-8")), clazz, features);
try {
return (T) parseObject(new String(input, "UTF-8"), clazz, features);
} catch (UnsupportedEncodingException e) {
throw new JSONException("UTF-8 not support");
}
}
@SuppressWarnings("unchecked")