Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: eunm encode in request get error #203

Merged
merged 4 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
44 changes: 42 additions & 2 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package hessian

import (
"reflect"
"strconv"
"testing"
"time"
)
Expand All @@ -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",
Expand All @@ -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) {
Expand Down