private void decodeSofaResponse(AbstractByteBuf data, SofaResponse sofaResponse, Map<String, String> head) {
        if (head == null) {
            throw buildDeserializeError("head is null!");
        }
        String targetService = head.remove(RemotingConstants.HEAD_TARGET_SERVICE);
        if (targetService == null) {
            throw buildDeserializeError("HEAD_TARGET_SERVICE is null");
        }
        String methodName = head.remove(RemotingConstants.HEAD_METHOD_NAME);
        if (methodName == null) {
            throw buildDeserializeError("HEAD_METHOD_NAME is null");
        }

        boolean isError = false;
        if (StringUtils.TRUE.equals(head.remove(RemotingConstants.HEAD_RESPONSE_ERROR))) {
            isError = true;
        }
        if (!head.isEmpty()) {
            sofaResponse.setResponseProps(head);
        }
        if (isError) {
            String errorMessage = (String) decode(data, String.class, head);
            if (errorMessage == null) {
                errorMessage = "";
            }
            sofaResponse.setErrorMsg(errorMessage);
        } else {
            // according interface and method name to find paramter types
            JavaType respType = jacksonHelper.getResClass(targetService, methodName);
            Object result;
            try {
                result = mapper.readValue(data.array(), respType);
            } catch (IOException e) {
                throw buildDeserializeError(e.getMessage());
            }
            sofaResponse.setAppResponse(result);
        }
    }
@Test
    public void testDecodeSofaResponse() {
        AbstractByteBuf nullByteBuf = serializer.encode(null, null);
        JacksonSerializer jacksonSerializer = new JacksonSerializer();
        SofaResponse sofaResponse = new SofaResponse();
        Map<String, String> ctx = new HashMap<>();
        ctx.put(RemotingConstants.HEAD_TARGET_SERVICE, "xxx");
        ctx.put(RemotingConstants.HEAD_METHOD_NAME, "xxx");
        ctx.put(RemotingConstants.HEAD_RESPONSE_ERROR, "true");
        jacksonSerializer.decode(nullByteBuf, sofaResponse, ctx);
        Assert.assertTrue(sofaResponse.isError());
        Assert.assertEquals("", sofaResponse.getErrorMsg());
    }