diff --git a/request.go b/request.go index 020c7897..82c1ef5e 100644 --- a/request.go +++ b/request.go @@ -97,7 +97,8 @@ func getArgType(v interface{}) string { case map[interface{}]interface{}: // return "java.util.HashMap" return "java.util.Map" - + case POJOEnum: + return v.(POJOEnum).JavaClassName() // Serialized tags for complex types default: t := reflect.TypeOf(v) diff --git a/request_test.go b/request_test.go index b5886db3..2b7f1f33 100644 --- a/request_test.go +++ b/request_test.go @@ -19,6 +19,7 @@ package hessian import ( "reflect" + "strconv" "testing" "time" ) @@ -27,6 +28,45 @@ import ( "github.com/stretchr/testify/assert" ) +type TestEnumGender JavaEnum + +const ( + MAN JavaEnum = iota + WOMAN +) + +var genderName = map[JavaEnum]string{ + MAN: "MAN", + WOMAN: "WOMAN", +} + +var genderValue = map[string]JavaEnum{ + "MAN": MAN, + "WOMAN": WOMAN, +} + +func (g TestEnumGender) JavaClassName() string { + return "com.ikurento.test.TestEnumGender" +} + +func (g TestEnumGender) String() string { + s, ok := genderName[JavaEnum(g)] + if ok { + return s + } + + return strconv.Itoa(int(g)) +} + +func (g TestEnumGender) EnumValue(s string) JavaEnum { + v, ok := genderValue[s] + if ok { + return v + } + + return InvalidJavaEnum +} + func TestPackRequest(t *testing.T) { bytes, err := packRequest(Service{ Path: "test", @@ -49,9 +89,9 @@ func TestPackRequest(t *testing.T) { func TestGetArgsTypeList(t *testing.T) { type Test struct{} - str, err := getArgsTypeList([]interface{}{nil, 1, []int{2}, true, []bool{false}, "a", []string{"b"}, Test{}, &Test{}, []Test{}, map[string]Test{}}) + str, err := getArgsTypeList([]interface{}{nil, 1, []int{2}, true, []bool{false}, "a", []string{"b"}, Test{}, &Test{}, []Test{}, map[string]Test{}, TestEnumGender(MAN)}) assert.NoError(t, err) - assert.Equal(t, "VJ[JZ[ZLjava/lang/String;[Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;Ljava/util/Map;", str) + assert.Equal(t, "VJ[JZ[ZLjava/lang/String;[Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;Ljava/util/Map;Lcom/ikurento/test/TestEnumGender;", str) } func TestDescRegex(t *testing.T) {