@Override
    public void decodeObjectByTemplate(AbstractByteBuf data, Map<String, String> context, SofaResponse template)
        throws SofaRpcException {
        try {
            UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(data.array());
            Hessian2Input input = new Hessian2Input(inputStream);
            // 根据SerializeType信息决定序列化器
            boolean genericSerialize = context != null && isGenericResponse(
                context.get(RemotingConstants.HEAD_GENERIC_TYPE));
            if (genericSerialize) {
                input.setSerializerFactory(genericSerializerFactory);
                GenericObject genericObject = (GenericObject) input.readObject();
                template.setErrorMsg((String) genericObject.getField("errorMsg"));
                template.setAppResponse(judgeCustomThrowableForGenericObject(genericObject.getField("appResponse")));
                template.setResponseProps((Map<String, String>) genericObject.getField("responseProps"));
            } else {
                input.setSerializerFactory(serializerFactory);
                SofaResponse tmp = (SofaResponse) input.readObject();
                // copy values to template
                template.setErrorMsg(tmp.getErrorMsg());
                template.setAppResponse(tmp.getAppResponse());
                template.setResponseProps(tmp.getResponseProps());
            }
            input.close();
        } catch (IOException e) {
            throw buildDeserializeError(e.getMessage(), e);
        }
    }
@Test
    public void testCustomThrowableDeserializerEnabled() throws Exception {
        setGenericThrowException(true);
        try {
            GenericMultipleClassLoaderSofaSerializerFactory factory = new GenericMultipleClassLoaderSofaSerializerFactory();
            SofaResponseHessianSerializer serializer = new SofaResponseHessianSerializer(null, factory);

            ByteArrayOutputStream bsOut = new ByteArrayOutputStream();
            Hessian2Output hessian2Output = new Hessian2Output(bsOut);
            hessian2Output.setSerializerFactory(factory);

            SofaResponse sofaResponse = new SofaResponse();
            MockError mockError = new MockError("MockError");
            sofaResponse.setAppResponse(mockError);
            hessian2Output.writeObject(sofaResponse);
            hessian2Output.flush();

            ByteArrayWrapperByteBuf bsIn = new ByteArrayWrapperByteBuf(bsOut.toByteArray());
            Map<String, String> ctx = new HashMap<>();
            ctx.put(RemotingConstants.HEAD_GENERIC_TYPE, "2");
            SofaResponse sofaResponse2 = new SofaResponse();
            serializer.decodeObjectByTemplate(bsIn, ctx, sofaResponse2);
            Assert.assertTrue(sofaResponse2.getAppResponse() instanceof MockError);
            Assert.assertEquals("MockError", ((MockError) sofaResponse2.getAppResponse()).getMessage());
        } finally {
            setGenericThrowException(false);
            clearCacheDeserializerMap();
        }
    }