You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by wo...@apache.org on 2021/12/03 10:09:07 UTC

[dubbo-go-hessian2] branch master updated: support java function param type (#295)

This is an automated email from the ASF dual-hosted git repository.

wongoo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-go-hessian2.git


The following commit(s) were added to refs/heads/master by this push:
     new 2fd463b  support java function param type (#295)
2fd463b is described below

commit 2fd463b75f652e34d2fbd3748e6408cd1e7f5664
Author: binbin.zhang <bb...@163.com>
AuthorDate: Fri Dec 3 18:08:59 2021 +0800

    support java function param type (#295)
    
    * support java function param type
    
    * update readme.md
    
    Co-authored-by: sanxun0325 <bbz17640380550.com>
---
 README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 param.go  | 28 ++++++++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 2cb4f5b..0f152c2 100644
--- a/README.md
+++ b/README.md
@@ -195,8 +195,74 @@ type MyUser struct {
 
 ```
 
+#### Encoding param name
 
-##### hessian.SetTagIdentifier
+When a Java method declares an argument as a parent class, it actually hope receives a subclass,
+You can specify the encoding type of the parameter separately.
+
+##### java-server
+
+```java
+public abstract class User {
+}
+
+public class MyUser extends User implements Serializable {
+
+    private String userFullName;
+
+    private String familyPhoneNumber;
+}
+
+public interface UserProvider {
+    String GetUser(User user);
+}
+
+public class UserProviderImpl implements UserProvider {
+    public UserProviderImpl() {
+    }
+    
+    public String GetUser(User user) {
+        MyUser myUser=(MyUser)user;
+        return myUser.getUserFullName();
+    }
+}
+
+```
+
+##### go-client
+
+```go
+type MyUser struct {
+    UserFullName      string   `hessian:"userFullName"`
+    FamilyPhoneNumber string   // default convert to => familyPhoneNumber
+}
+
+func (m *MyUser) JavaClassName() string {
+    return "com.company.MyUser"
+}
+
+func (m *MyUser) JavaParamName() string {
+    return "com.company.User"
+}
+
+type UserProvider struct {
+    GetUser func(ctx context.Context, user *MyUser) (string, error) `dubbo:"GetUser"`
+}
+```
+
+
+
+#### Set method Alias
+
+When the Go client calls the Java server, the first letter of the method is converted to lowercase by default,you can use the dubbo tag to set method alias.
+
+```go
+type UserProvider struct {
+    GetUser func(ctx context.Context) (*User, error) `dubbo:"GetUser"`
+}
+```
+
+#### hessian.SetTagIdentifier
 
 You can use `hessian.SetTagIdentifier` to customize tag-identifier of hessian, which takes effect to both encoder and decoder.
 
@@ -237,6 +303,7 @@ The encoded bytes of the struct `MyUser` is as following:
 ```
 
 #### Using Java collections
+
 By default, the output of Hessian Java impl of a Java collection like java.util.HashSet will be decoded as `[]interface{}` in `go-hessian2`.
 To apply the one-to-one mapping relationship between certain Java collection class and your Go struct, examples are as follows:
 
diff --git a/param.go b/param.go
new file mode 100644
index 0000000..f30f761
--- /dev/null
+++ b/param.go
@@ -0,0 +1,28 @@
+/*
+ * 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 hessian
+
+// Param interface
+// !!! Pls attention that Every field name should be upper case.
+// specifies the Java method parameter type.
+// if this interface is not implemented, the pojo javaClassName is
+// used as the method parameter type by default
+type Param interface {
+	POJO
+	JavaParamName() string
+}