public void onResponse()

in dubbo-rpc/dubbo-rpc-api/src/main/java/org/apache/dubbo/rpc/filter/GenericFilter.java [305:378]


    public void onResponse(Result appResponse, Invoker<?> invoker, Invocation inv) {
        if ((inv.getMethodName().equals($INVOKE) || inv.getMethodName().equals($INVOKE_ASYNC))
                && inv.getArguments() != null
                && inv.getArguments().length == 3
                && !GenericService.class.isAssignableFrom(invoker.getInterface())) {

            String generic = inv.getAttachment(GENERIC_KEY);
            if (StringUtils.isBlank(generic)) {
                generic = getGenericValueFromRpcContext();
            }

            if (appResponse.hasException()
                    && Dubbo2CompactUtils.isEnabled()
                    && Dubbo2GenericExceptionUtils.isGenericExceptionClassLoaded()) {
                Throwable appException = appResponse.getException();
                if (appException instanceof GenericException) {
                    GenericException tmp = (GenericException) appException;
                    GenericException recreated = Dubbo2GenericExceptionUtils.newGenericException(
                            tmp.getMessage(), tmp.getCause(), tmp.getExceptionClass(), tmp.getExceptionMessage());
                    if (recreated != null) {
                        appException = recreated;
                    }
                    appException.setStackTrace(tmp.getStackTrace());
                }
                if (!(Dubbo2GenericExceptionUtils.getGenericExceptionClass()
                        .isAssignableFrom(appException.getClass()))) {
                    GenericException recreated = Dubbo2GenericExceptionUtils.newGenericException(appException);
                    if (recreated != null) {
                        appException = recreated;
                    }
                }
                appResponse.setException(appException);
            }
            if (ProtocolUtils.isGenericReturnRawResult(generic)) {
                return;
            }
            if (ProtocolUtils.isJavaGenericSerialization(generic)) {
                try {
                    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream(512);
                    applicationModel
                            .getExtensionLoader(Serialization.class)
                            .getExtension(GENERIC_SERIALIZATION_NATIVE_JAVA)
                            .serialize(null, os)
                            .writeObject(appResponse.getValue());
                    appResponse.setValue(os.toByteArray());
                } catch (IOException e) {
                    throw new RpcException(
                            "Generic serialization [" + GENERIC_SERIALIZATION_NATIVE_JAVA
                                    + "] serialize result failed.",
                            e);
                }
            } else if (ProtocolUtils.isBeanGenericSerialization(generic)) {
                appResponse.setValue(JavaBeanSerializeUtil.serialize(appResponse.getValue(), JavaBeanAccessor.METHOD));
            } else if (ProtocolUtils.isProtobufGenericSerialization(generic)) {
                try {
                    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream(512);
                    applicationModel
                            .getExtensionLoader(Serialization.class)
                            .getExtension(GENERIC_SERIALIZATION_PROTOBUF)
                            .serialize(null, os)
                            .writeObject(appResponse.getValue());
                    appResponse.setValue(os.toString());
                } catch (IOException e) {
                    throw new RpcException(
                            "Generic serialization [" + GENERIC_SERIALIZATION_PROTOBUF + "] serialize result failed.",
                            e);
                }
            } else if (ProtocolUtils.isGsonGenericSerialization(generic)) {
                appResponse.setValue(GsonUtils.toJson(appResponse.getValue()));
            } else {
                appResponse.setValue(PojoUtils.generalize(appResponse.getValue()));
            }
        }
    }