提交 aef4dbd7 编写于 作者: W william.liangf

修改FastJson对异常的处理

git-svn-id: http://code.alibabatech.com/svn/dubbo/trunk@627 1a56cb94-b969-4eaa-88fa-be21384802f2
上级 ef992d2d
......@@ -22,7 +22,6 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Type;
import java.util.Map;
import com.alibaba.dubbo.common.serialize.ObjectInput;
import com.alibaba.dubbo.common.utils.PojoUtils;
......@@ -113,29 +112,20 @@ public class FastJsonObjectInput implements ObjectInput {
return readLine().getBytes();
}
@SuppressWarnings("unchecked")
public Object readObject() throws IOException, ClassNotFoundException {
String json = readLine();
if (json.startsWith("{")) {
return JSON.parseObject(json, Map.class);
} else {
json = "{\"value\":" + json + "}";
Map<String, Object> map = JSON.parseObject(json, Map.class);
return map.get("value");
}
return JSON.parse(json);
}
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
Object value = readObject();
return (T) PojoUtils.realize(value, cls);
// return JSON.parseObject(readLine(), cls);
String json = readLine();
return JSON.parseObject(json, cls);
}
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls, Type type) throws IOException,ClassNotFoundException
{
Object value = readObject();
Object value = readObject(cls);
return (T) PojoUtils.realize(value, cls, type);
}
......
......@@ -84,15 +84,11 @@ public class FastJsonObjectOutput implements ObjectOutput {
}
public void writeObject(Object obj) throws IOException {
if (obj instanceof Throwable) {
writer.write("{\"message\":\"" + ((Throwable)obj).getMessage() + "\"}");
} else {
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.WriteEnumUsingToString, true);
serializer.write(obj);
out.writeTo(writer);
}
SerializeWriter out = new SerializeWriter();
JSONSerializer serializer = new JSONSerializer(out);
serializer.config(SerializerFeature.WriteEnumUsingToString, true);
serializer.write(obj);
out.writeTo(writer);
writer.println();
writer.flush();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册