@Test
    public void encodeSofaRequest() throws Exception {
        SofaRequest request = buildRequest();
        AbstractByteBuf data = serializer.encode(request, null);
        SofaRequest newRequest = (SofaRequest) serializer.decode(data, SofaRequest.class, null);

        Assert.assertEquals(newRequest.getInterfaceName(), request.getInterfaceName());
        Assert.assertEquals(newRequest.getMethodName(), request.getMethodName());
        Assert.assertArrayEquals(newRequest.getMethodArgSigs(), request.getMethodArgSigs());
        Assert.assertEquals(newRequest.getMethodArgs().length, request.getMethodArgs().length);
        Assert.assertEquals(newRequest.getTargetServiceUniqueName(), request.getTargetServiceUniqueName());
        Assert.assertEquals(newRequest.getTargetAppName(), request.getTargetAppName());

        request = buildRequest();
        GenericObject genericObject = new GenericObject(TestGenericBean.class.getCanonicalName());
        genericObject.putField("name", "Lilei");
        genericObject.putField("age", 123);
        request.setMethodArgSigs(new String[] { TestGenericBean.class.getCanonicalName() }); // change to generic request
        request.setMethodArgs(new Object[] { genericObject });
        data = serializer.encode(request, Collections.singletonMap(RemotingConstants.HEAD_GENERIC_TYPE,
            RemotingConstants.SERIALIZE_FACTORY_GENERIC));
        newRequest = (SofaRequest) serializer.decode(data, SofaRequest.class, null);
        Assert.assertEquals(newRequest.getInterfaceName(), request.getInterfaceName());
        Assert.assertEquals(newRequest.getMethodName(), request.getMethodName());
        Assert.assertArrayEquals(newRequest.getMethodArgSigs(), request.getMethodArgSigs());
        Assert.assertEquals(newRequest.getMethodArgs().length, request.getMethodArgs().length);
        Assert.assertEquals(TestGenericBean.class.getCanonicalName(), newRequest.getMethodArgs()[0].getClass()
            .getCanonicalName());
        Assert.assertEquals(newRequest.getTargetServiceUniqueName(), request.getTargetServiceUniqueName());
        Assert.assertEquals(newRequest.getTargetAppName(), request.getTargetAppName());

        // error request has no target service name
        request = buildRequest();
        request.setTargetServiceUniqueName(null);
        data = serializer.encode(request, null);
        boolean error = false;
        try {
            serializer.decode(data, SofaRequest.class, null);
        } catch (Exception e) {
            error = true;
        }
        Assert.assertTrue(error);
    }
@author <a href="mailto:zhanggeng.zg@antfin.com">GengZhang</a>
codec/codec-sofa-hessian/src/test/java/com/alipay/sofa/rpc/codec/sofahessian/SofaHessianSerializerTest.java