Skip to content

Commit

Permalink
hessian2 support setting type of Java method parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin0325 committed Dec 6, 2021
1 parent 7bb88bf commit 26e3a78
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions protocol/dubbo/impl/hessian.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,10 @@ func getArgType(v interface{}) string {
}
switch t.Kind() {
case reflect.Struct:
p, ok := v.(hessian.Param)
if ok {
return p.JavaParamName()
}
v, ok := v.(hessian.POJO)
if ok {
return v.JavaClassName()
Expand Down
60 changes: 60 additions & 0 deletions protocol/dubbo/impl/hessian_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 impl

import (
"testing"
)

import (
"github.com/stretchr/testify/assert"
)

const (
dubboParam = "org.apache.dubbo.param"
dubboPojo = "org.apache.dubbo.pojo"
)

type Param struct {
}

func (p *Param) JavaClassName() string {
return dubboPojo
}

func (p *Param) JavaParamName() string {
return dubboParam
}

type Pojo struct {
}

func (p *Pojo) JavaClassName() string {
return dubboPojo
}

func TestGetArgType(t *testing.T) {

t.Run("pojo", func(t *testing.T) {
assert.Equal(t, dubboPojo, getArgType(&Pojo{}))
})

t.Run("param", func(t *testing.T) {
assert.Equal(t, dubboParam, getArgType(&Param{}))
})
}

0 comments on commit 26e3a78

Please sign in to comment.