diff --git a/dubbo-common/pom.xml b/dubbo-common/pom.xml
index f59666e545..d0c050673a 100644
--- a/dubbo-common/pom.xml
+++ b/dubbo-common/pom.xml
@@ -99,5 +99,10 @@
javax.annotation
javax.annotation-api
+
+ com.google.protobuf
+ protobuf-java
+ test
+
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ProtobufUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ProtobufUtils.java
new file mode 100644
index 0000000000..a126fc61cd
--- /dev/null
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ProtobufUtils.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.common.utils;
+
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
+
+import static org.apache.dubbo.common.constants.CommonConstants.PROTOBUF_MESSAGE_CLASS_NAME;
+
+public class ProtobufUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(ProtobufUtils.class);
+
+ private static Class> protobufClss;
+
+ private ProtobufUtils() {}
+
+ static {
+ try {
+ protobufClss = ClassUtils.forName(PROTOBUF_MESSAGE_CLASS_NAME, ProtobufUtils.class.getClassLoader());
+ } catch (Throwable t) {
+ logger.info("protobuf's dependency is absent");
+ }
+ }
+
+ public static boolean isProtobufClass(Class> pojoClazz) {
+ if (protobufClss != null) {
+ return protobufClss.isAssignableFrom(pojoClazz);
+ }
+ return false;
+ }
+}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ProtobufUtilsTest.java b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ProtobufUtilsTest.java
new file mode 100644
index 0000000000..e7ca7bc01b
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/ProtobufUtilsTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.common.utils;
+
+import org.apache.dubbo.common.vo.UserVo;
+import org.apache.dubbo.rpc.model.HelloReply;
+import org.apache.dubbo.rpc.model.HelloRequest;
+import org.apache.dubbo.rpc.model.Person;
+import org.apache.dubbo.rpc.model.SerializablePerson;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class ProtobufUtilsTest {
+
+ @Test
+ void testIsProtobufClass() {
+ Assertions.assertTrue(ProtobufUtils.isProtobufClass(HelloRequest.class));
+ Assertions.assertTrue(ProtobufUtils.isProtobufClass(HelloReply.class));
+ Assertions.assertFalse(ProtobufUtils.isProtobufClass(Person.class));
+ Assertions.assertFalse(ProtobufUtils.isProtobufClass(SerializablePerson.class));
+ Assertions.assertFalse(ProtobufUtils.isProtobufClass(UserVo.class));
+ }
+}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloReply.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloReply.java
new file mode 100644
index 0000000000..3ecd4585e5
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloReply.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.model;
+
+import com.google.protobuf.Message;
+
+public final class HelloReply extends com.google.protobuf.GeneratedMessageV3 {
+
+ @Override
+ protected FieldAccessorTable internalGetFieldAccessorTable() {
+ return null;
+ }
+
+ @Override
+ protected Message.Builder newBuilderForType(BuilderParent builderParent) {
+ return null;
+ }
+
+ @Override
+ public Message.Builder newBuilderForType() {
+ return null;
+ }
+
+ @Override
+ public Message.Builder toBuilder() {
+ return null;
+ }
+
+ @Override
+ public Message getDefaultInstanceForType() {
+ return null;
+ }
+}
diff --git a/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloRequest.java b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloRequest.java
new file mode 100644
index 0000000000..1ea1cc6136
--- /dev/null
+++ b/dubbo-common/src/test/java/org/apache/dubbo/rpc/model/HelloRequest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.rpc.model;
+
+import com.google.protobuf.Message;
+
+public final class HelloRequest extends com.google.protobuf.GeneratedMessageV3 {
+
+ @Override
+ protected FieldAccessorTable internalGetFieldAccessorTable() {
+ return null;
+ }
+
+ @Override
+ protected Message.Builder newBuilderForType(BuilderParent builderParent) {
+ return null;
+ }
+
+ @Override
+ public Message.Builder newBuilderForType() {
+ return null;
+ }
+
+ @Override
+ public Message.Builder toBuilder() {
+ return null;
+ }
+
+ @Override
+ public Message getDefaultInstanceForType() {
+ return null;
+ }
+}
diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
index 4c19ca2d12..046410a20d 100644
--- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
+++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/ReflectionPackableMethod.java
@@ -41,7 +41,7 @@ import java.util.stream.Stream;
import com.google.protobuf.Message;
import static org.apache.dubbo.common.constants.CommonConstants.$ECHO;
-import static org.apache.dubbo.common.constants.CommonConstants.PROTOBUF_MESSAGE_CLASS_NAME;
+import static org.apache.dubbo.common.utils.ProtobufUtils.isProtobufClass;
public class ReflectionPackableMethod implements PackableMethod {
@@ -269,21 +269,6 @@ public class ReflectionPackableMethod implements PackableMethod {
return RX_RETURN_CLASS.equalsIgnoreCase(clz.getName());
}
- static boolean isProtobufClass(Class> clazz) {
- while (clazz != Object.class && clazz != null) {
- Class>[] interfaces = clazz.getInterfaces();
- if (interfaces.length > 0) {
- for (Class> clazzInterface : interfaces) {
- if (PROTOBUF_MESSAGE_CLASS_NAME.equalsIgnoreCase(clazzInterface.getName())) {
- return true;
- }
- }
- }
- clazz = clazz.getSuperclass();
- }
- return false;
- }
-
private static String convertHessianFromWrapper(String serializeType) {
if (TripleConstant.HESSIAN4.equals(serializeType)) {
return TripleConstant.HESSIAN2;