Skip to content
Permalink
Browse files
go to java list and array (#265)
  • Loading branch information
wongoo committed May 6, 2021
1 parent 3fddc30 commit 6f053c6c6b3a572f3388f22e0056c5e7b412f1c0
Showing 5 changed files with 159 additions and 0 deletions.
@@ -40,6 +40,8 @@ func init() {
funcMap["Java8TimeYear"] = testfuncs.Java8TimeYear
funcMap["Java8LocalDate"] = testfuncs.Java8LocalDate
funcMap["JavaException"] = testfuncs.JavaException
funcMap["UserArray"] = testfuncs.UserArray
funcMap["UserList"] = testfuncs.UserList
}

func main() {
@@ -0,0 +1,38 @@
/*
* 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 testfuncs

import (
hessian "github.com/apache/dubbo-go-hessian2"
)

func UserArray() []byte {
e := hessian.NewEncoder()
_ = e.Encode([]*User{
{"wongoo"}, {"alex"},
})
return e.Buffer()
}

func UserList() []byte {
e := hessian.NewEncoder()
_ = e.Encode([]interface{}{
&User{"wongoo"}, &User{"alex"},
})
return e.Buffer()
}
@@ -0,0 +1,33 @@
/*
* 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 testfuncs

import hessian "github.com/apache/dubbo-go-hessian2"

type User struct {
Name string
}

// JavaClassName java fully qualified path
func (*User) JavaClassName() string {
return "test.model.User"
}

func init() {
hessian.RegisterPOJO(&User{})
}
@@ -0,0 +1,46 @@
/*
* 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 test.model;

import java.io.Serializable;

public class User implements Serializable {
private String name;

public User() {
}

public User(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
'}';
}
}
@@ -0,0 +1,40 @@
/*
* 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 unit;


import org.junit.Test;
import test.model.User;

import java.util.Arrays;
import java.util.List;

/**
* @author wongoo
*/
public class GoUserListTest {

@Test
public void testUserList() {
User[] userArray = (User[]) GoTestUtil.readGoObject("UserArray");
System.out.println(Arrays.toString(userArray));

List<User> userList = (List<User>) GoTestUtil.readGoObject("UserList");
System.out.println(userList);
}
}

0 comments on commit 6f053c6

Please sign in to comment.