mirror of https://github.com/goccy/go-json.git
Compare commits
6 Commits
c69f39c117
...
9d7582fa11
Author | SHA1 | Date |
---|---|---|
a | 9d7582fa11 | |
Masaaki Goshima | 3e9769d637 | |
Andrey Grazhdankov | 65c8b28ca1 | |
a | 3918cb256f | |
a | 260c426a4c | |
a | 76a5d06ee7 |
|
@ -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
|
||||||
|
|
|
@ -84,7 +84,9 @@ func (e *Encoder) encodeWithOption(ctx *encoder.RuntimeContext, v interface{}, o
|
||||||
} else {
|
} else {
|
||||||
buf = buf[:len(buf)-1]
|
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 {
|
if _, err := e.w.Write(buf); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -24,6 +24,7 @@ type Option struct {
|
||||||
Context context.Context
|
Context context.Context
|
||||||
DebugOut io.Writer
|
DebugOut io.Writer
|
||||||
DebugDOTOut io.WriteCloser
|
DebugDOTOut io.WriteCloser
|
||||||
|
DisableNewline bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type EncodeFormat struct {
|
type EncodeFormat struct {
|
||||||
|
|
Loading…
Reference in New Issue