diff --git a/Makefile b/Makefile index 7717c1e..7cfec87 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ all: test .root/src/$(PKG): mkdir -p $@ - for i in $$PWD/* ; do ln -s $$i $@/`basename $$i` ; done + for i in $$PWD/* ; do ln -s $$i $@/`basename $$i` ; done root: .root/src/$(PKG) @@ -27,7 +27,7 @@ generate: root build .root/src/$(PKG)/tests/custom_map_key_type.go \ .root/src/$(PKG)/tests/embedded_type.go - .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go + .root/bin/easyjson -all .root/src/$(PKG)/tests/data.go .root/bin/easyjson -all .root/src/$(PKG)/tests/nothing.go .root/bin/easyjson -all .root/src/$(PKG)/tests/errors.go .root/bin/easyjson -snake_case .root/src/$(PKG)/tests/snake.go diff --git a/gen/decoder.go b/gen/decoder.go index 5dc1249..606602f 100644 --- a/gen/decoder.go +++ b/gen/decoder.go @@ -114,7 +114,7 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field tmpVar := g.uniqueVarName() elem := t.Elem() - if elem.Kind() == reflect.Uint8 { + if elem.Kind() == reflect.Uint8 && elem.Name() == "uint8" { fmt.Fprintln(g.out, ws+"if in.IsNull() {") fmt.Fprintln(g.out, ws+" in.Skip()") fmt.Fprintln(g.out, ws+" "+out+" = nil") @@ -161,7 +161,7 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field iterVar := g.uniqueVarName() elem := t.Elem() - if elem.Kind() == reflect.Uint8 { + if elem.Kind() == reflect.Uint8 && elem.Name() == "uint8" { fmt.Fprintln(g.out, ws+"if in.IsNull() {") fmt.Fprintln(g.out, ws+" in.Skip()") fmt.Fprintln(g.out, ws+"} else {") diff --git a/gen/encoder.go b/gen/encoder.go index 293a66a..b2be743 100644 --- a/gen/encoder.go +++ b/gen/encoder.go @@ -137,7 +137,7 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT iVar := g.uniqueVarName() vVar := g.uniqueVarName() - if t.Elem().Kind() == reflect.Uint8 { + if t.Elem().Kind() == reflect.Uint8 && elem.Name() == "uint8" { fmt.Fprintln(g.out, ws+"out.Base64Bytes("+in+")") } else { if !assumeNonEmpty { @@ -166,7 +166,7 @@ func (g *Generator) genTypeEncoderNoCheck(t reflect.Type, in string, tags fieldT elem := t.Elem() iVar := g.uniqueVarName() - if t.Elem().Kind() == reflect.Uint8 { + if t.Elem().Kind() == reflect.Uint8 && elem.Name() == "uint8" { fmt.Fprintln(g.out, ws+"out.Base64Bytes("+in+"[:])") } else { fmt.Fprintln(g.out, ws+"out.RawByte('[')") diff --git a/tests/basic_test.go b/tests/basic_test.go index ab166f3..3b1cc65 100644 --- a/tests/basic_test.go +++ b/tests/basic_test.go @@ -50,6 +50,8 @@ var testCases = []struct { {&mapUintptrStringValue, mapUintptrStringValueString}, {&intKeyedMapStructValue, intKeyedMapStructValueString}, {&intArrayStructValue, intArrayStructValueString}, + {&myUInt8SliceValue, myUInt8SliceString}, + {&myUInt8ArrayValue, myUInt8ArrayString}, } func TestMarshal(t *testing.T) { diff --git a/tests/data.go b/tests/data.go index 8d5132d..6ae90a0 100644 --- a/tests/data.go +++ b/tests/data.go @@ -784,3 +784,19 @@ var intArrayStructValueString = `{` + `"pointer":[1,2],` + `"value":[1,2]` + `}` + +type MyUInt8 uint8 + +//easyjson:json +type MyUInt8Slice []MyUInt8 + +var myUInt8SliceValue = MyUInt8Slice{1, 2, 3, 4, 5} + +var myUInt8SliceString = `[1,2,3,4,5]` + +//easyjson:json +type MyUInt8Array [2]MyUInt8 + +var myUInt8ArrayValue = MyUInt8Array{1, 2} + +var myUInt8ArrayString = `[1,2]`