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