@Test
    public void testInvokeContextCustomSerializer_CALLBACK() throws Exception {
        NormalRequestBodyCustomSerializer_InvokeContext s1 = new NormalRequestBodyCustomSerializer_InvokeContext();
        NormalStringCustomSerializer_InvokeContext s2 = new NormalStringCustomSerializer_InvokeContext();
        CustomSerializerManager.registerCustomSerializer(RequestBody.class.getName(), s1);
        CustomSerializerManager.registerCustomSerializer(String.class.getName(), s2);

        RequestBody body = new RequestBody(1, "hello world!");
        InvokeContext invokeContext = new InvokeContext();
        invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY,
            NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE1_value);

        final List<Object> rets = new ArrayList<Object>();
        final CountDownLatch latch = new CountDownLatch(1);
        client.invokeWithCallback(addr, body, invokeContext, new InvokeCallback() {
            @Override
            public void onResponse(Object result) {
                rets.clear();
                rets.add(result);
                latch.countDown();
            }

            @Override
            public void onException(Throwable e) {

            }

            @Override
            public Executor getExecutor() {
                return null;
            }
        }, 1000);
        latch.await();
        String ret = (String) rets.get(0);
        Assert.assertEquals(RequestBody.DEFAULT_SERVER_RETURN_STR + "RANDOM", ret);
        Assert.assertTrue(s1.isSerialized());
        Assert.assertTrue(s1.isDeserialized());

        invokeContext.clear();
        invokeContext.putIfAbsent(NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE_KEY,
            NormalRequestBodyCustomSerializer_InvokeContext.SERIALTYPE2_value);
        final CountDownLatch latch1 = new CountDownLatch(1);
        client.invokeWithCallback(addr, body, invokeContext, new InvokeCallback() {
            @Override
            public void onResponse(Object result) {
                rets.clear();
                rets.add(result);
                latch1.countDown();
            }

            @Override
            public void onException(Throwable e) {

            }

            @Override
            public Executor getExecutor() {
                return null;
            }
        }, 1000);
        latch1.await();
        ret = (String) rets.get(0);
        Assert.assertEquals(NormalStringCustomSerializer_InvokeContext.UNIVERSAL_RESP, ret);
        Assert.assertTrue(s1.isSerialized());
        Assert.assertTrue(s1.isDeserialized());
    }
test custom serializer using invoke contxt in callback
@throws Exception
src/test/java/com/alipay/remoting/rpc/serializer/ClassCustomSerializerTest.java