Skip to content
Browse files
support java function param type (#295)
* support java function param type

* update

Co-authored-by: sanxun0325 <>
  • Loading branch information
sanxun0325 committed Dec 3, 2021
1 parent 7cabe51 commit 2fd463b75f652e34d2fbd3748e6408cd1e7f5664
Showing 2 changed files with 96 additions and 1 deletion.
@@ -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

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

type MyUser struct {
UserFullName string `hessian:"userFullName"`
FamilyPhoneNumber string // default convert to => familyPhoneNumber
func (m *MyUser) JavaClassName() string {
return ""
func (m *MyUser) JavaParamName() string {
return ""
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.

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:

@@ -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
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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 {
JavaParamName() string

0 comments on commit 2fd463b

Please sign in to comment.