Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
feat(*): add Integer[] serializer
- Loading branch information
dongjianhui03
committed
Sep 13, 2021
1 parent
8679ff8
commit 4d7455534f6582fcf28110dc6f17b7befeb15ab1
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,31 @@ | ||
package hessian | ||
|
||
func init() { | ||
SetCollectionSerialize(&IntegerArray{}) | ||
} | ||
|
||
type IntegerArray struct { | ||
Values []int32 | ||
} | ||
|
||
func (ia IntegerArray) Get() []interface{} { | ||
res := make([]interface{}, len(ia.Values)) | ||
for i, v := range ia.Values { | ||
res[i] = v | ||
} | ||
return res | ||
} | ||
|
||
func (ia IntegerArray) Set(vs []interface{}) { | ||
values := make([]int32, len(vs)) | ||
for i, v := range vs { | ||
values[i] = v.(int32) | ||
} | ||
ia.Values = values | ||
} | ||
|
||
func (IntegerArray) JavaClassName() string { | ||
return "[java.lang.Integer" | ||
} | ||
|
||
type ArraySerializer JavaCollectionSerializer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,18 @@ | ||
package hessian | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
var intArr = []int32{1, 2, 3} | ||
integerArray := IntegerArray{intArr} | ||
jcs := JavaCollectionSerializer{} | ||
e := &Encoder{} | ||
err := jcs.EncObject(e, integerArray) | ||
if err != nil { | ||
return | ||
} | ||
fmt.Printf("%v\n", e.buffer) | ||
} |