Skip to content
Permalink
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.
@@ -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
@@ -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)
}

0 comments on commit 4d74555

Please sign in to comment.