Compare commits

...

6 Commits

Author SHA1 Message Date
a 9d7582fa11
Merge 3918cb256f into 3e9769d637 2024-11-22 06:54:47 +00:00
Masaaki Goshima 3e9769d637
Update go.yml 2024-11-11 12:13:39 +09:00
Andrey Grazhdankov 65c8b28ca1
Fix encode []*time.Time - check nil (#524) 2024-11-11 11:10:21 +09:00
a 3918cb256f
Merge branch 'goccy:master' into master 2023-10-26 11:15:38 +02:00
a 260c426a4c
newline 2023-07-19 21:01:41 -05:00
a 76a5d06ee7
Update option.go 2023-07-19 21:00:53 -05:00
5 changed files with 15 additions and 2 deletions

View File

@ -12,7 +12,7 @@ jobs:
- name: checkout
uses: actions/checkout@v3
- name: build
run: docker-compose run go-json
run: docker compose run go-json
test:
name: Test

View File

@ -84,7 +84,9 @@ func (e *Encoder) encodeWithOption(ctx *encoder.RuntimeContext, v interface{}, o
} else {
buf = buf[:len(buf)-1]
}
buf = append(buf, '\n')
if !ctx.Option.DisableNewline {
buf = append(buf, '\n')
}
if _, err := e.w.Write(buf); err != nil {
return err
}

View File

@ -426,6 +426,11 @@ func Test_Marshal(t *testing.T) {
assertErr(t, err)
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) {

View File

@ -406,6 +406,11 @@ func AppendMarshalJSON(ctx *RuntimeContext, code *Opcode, b []byte, v interface{
rv = newV
}
}
if rv.Kind() == reflect.Ptr && rv.IsNil() {
return AppendNull(ctx, b), nil
}
v = rv.Interface()
var bb []byte
if (code.Flags & MarshalerContextFlags) != 0 {

View File

@ -24,6 +24,7 @@ type Option struct {
Context context.Context
DebugOut io.Writer
DebugDOTOut io.WriteCloser
DisableNewline bool
}
type EncodeFormat struct {