mirror of https://github.com/goccy/go-json.git
Compare commits
5 Commits
6b1bacc345
...
4d1202359b
Author | SHA1 | Date |
---|---|---|
guoguangwu | 4d1202359b | |
Masaaki Goshima | 3e9769d637 | |
Andrey Grazhdankov | 65c8b28ca1 | |
guoguangwu | 3a5cec6e36 | |
guoguangwu | 89c61b5424 |
|
@ -12,7 +12,7 @@ jobs:
|
||||||
- name: checkout
|
- name: checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: build
|
- name: build
|
||||||
run: docker-compose run go-json
|
run: docker compose run go-json
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Test
|
name: Test
|
||||||
|
|
|
@ -426,6 +426,11 @@ func Test_Marshal(t *testing.T) {
|
||||||
assertErr(t, err)
|
assertErr(t, err)
|
||||||
assertEq(t, "[]interface{}", `[1,2.1,"hello"]`, string(bytes))
|
assertEq(t, "[]interface{}", `[1,2.1,"hello"]`, string(bytes))
|
||||||
})
|
})
|
||||||
|
t.Run("[]*time.Time", func(t *testing.T) {
|
||||||
|
bytes, err := json.Marshal([]*time.Time{nil})
|
||||||
|
assertErr(t, err)
|
||||||
|
assertEq(t, "[]*time.Time", `[null]`, string(bytes))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("array", func(t *testing.T) {
|
t.Run("array", func(t *testing.T) {
|
||||||
|
|
|
@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
|
||||||
if idx < mapCtx.Len {
|
if idx < mapCtx.Len {
|
||||||
mapCtx.Idx = int(idx)
|
mapCtx.Idx = int(idx)
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
|
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
||||||
b = appendColon(ctx, b)
|
b = appendColon(ctx, b)
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
}
|
}
|
||||||
value := mapitervalue(&mapCtx.Iter)
|
value := mapitervalue(&mapCtx.Iter)
|
||||||
|
|
|
@ -406,6 +406,11 @@ func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{
|
||||||
rv = newV
|
rv = newV
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||||
|
return AppendNull(ctx, b), nil
|
||||||
|
}
|
||||||
|
|
||||||
v = rv.Interface()
|
v = rv.Interface()
|
||||||
var bb []byte
|
var bb []byte
|
||||||
if (code.Flags & MarshalerContextFlags) != 0 {
|
if (code.Flags & MarshalerContextFlags) != 0 {
|
||||||
|
|
|
@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
|
||||||
if idx < mapCtx.Len {
|
if idx < mapCtx.Len {
|
||||||
mapCtx.Idx = int(idx)
|
mapCtx.Idx = int(idx)
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
|
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
||||||
b = appendColon(ctx, b)
|
b = appendColon(ctx, b)
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
}
|
}
|
||||||
value := mapitervalue(&mapCtx.Iter)
|
value := mapitervalue(&mapCtx.Iter)
|
||||||
|
|
|
@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
|
||||||
if idx < mapCtx.Len {
|
if idx < mapCtx.Len {
|
||||||
mapCtx.Idx = int(idx)
|
mapCtx.Idx = int(idx)
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
|
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
||||||
b = appendColon(ctx, b)
|
b = appendColon(ctx, b)
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
}
|
}
|
||||||
value := mapitervalue(&mapCtx.Iter)
|
value := mapitervalue(&mapCtx.Iter)
|
||||||
|
|
|
@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
|
||||||
if idx < mapCtx.Len {
|
if idx < mapCtx.Len {
|
||||||
mapCtx.Idx = int(idx)
|
mapCtx.Idx = int(idx)
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
|
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
||||||
b = appendColon(ctx, b)
|
b = appendColon(ctx, b)
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
}
|
}
|
||||||
value := mapitervalue(&mapCtx.Iter)
|
value := mapitervalue(&mapCtx.Iter)
|
||||||
|
|
|
@ -437,7 +437,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
code = code.End.Next
|
code = code.End.Next
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Value = b[mapCtx.Start:]
|
||||||
if idx < mapCtx.Len {
|
if idx < mapCtx.Len {
|
||||||
mapCtx.Idx = int(idx)
|
mapCtx.Idx = int(idx)
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
|
@ -453,7 +453,7 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
|
||||||
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
if (ctx.Option.Flag & encoder.UnorderedMapOption) != 0 {
|
||||||
b = appendColon(ctx, b)
|
b = appendColon(ctx, b)
|
||||||
} else {
|
} else {
|
||||||
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:len(b)]
|
mapCtx.Slice.Items[mapCtx.Idx].Key = b[mapCtx.Start:]
|
||||||
mapCtx.Start = len(b)
|
mapCtx.Start = len(b)
|
||||||
}
|
}
|
||||||
value := mapitervalue(&mapCtx.Iter)
|
value := mapitervalue(&mapCtx.Iter)
|
||||||
|
|
Loading…
Reference in New Issue