com.caucho.hessian.io.HessianProtocolException: expected Hessian message (‘p‘) at end of file

Hessian序列化过程中遇到的异常:

 代码块:

public <T> byte[] serialize(T obj) {
        byte[] result = null;
        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        Hessian2Output  hessian2Output=new Hessian2Output(byteArrayOutputStream);
        try {
            System.out.println(obj);
            hessian2Output.startMessage();
            hessian2Output.writeObject(obj);
            //hessian2Output.flush();
            hessian2Output.completeMessage();
            result=byteArrayOutputStream.toByteArray();
            System.out.println("result="+result.length);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                if(null!=hessian2Output)
                {
                    hessian2Output.close();
                    byteArrayOutputStream.close();
                }
                return   result;
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        return new byte[0];
    }

 问题解决:

hessian2Output.startMessage();
hessian2Output.writeObject(obj);
hessian2Output.flush();//刷新一下写缓存
hessian2Output.completeMessage();
result=byteArrayOutputStream.toByteArray();

猜你喜欢

转载自blog.csdn.net/jason_jiahongfei/article/details/112604624