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

hessian2 supports setting the type of Java method parameters #1625

Merged
merged 1 commit into from
Dec 6, 2021
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
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)
Copy link
Member

@justxuewei justxuewei Dec 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Param name makes me confused, I think it's better if it is called inherited names and interfaces respectively.

BTW, I think inherited names and interfaces should return a string array to fit all inheritance scenarios. For instance, class A inherits from class B, and class B inherits from class C, so the return value of inherited names is []string{B, C}.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个看上去应该给hessian 提交个issue? @justxuewei

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{}))
})
}