-
-
Couldn't load subscription status.
- Fork 6.2k
use experimental go json v2 library #35392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c5f251b
cb16b33
abc734c
f9c8805
9d83440
31492c1
7b0832c
fe51938
29d1770
3c3f77f
ce4107d
b8fb94d
c748ca8
f9d91f2
7fec838
3c6d690
b3969be
ba43047
94d537c
82b2d97
502b4fb
d4b1e10
8f3b218
34af20c
a65bff4
cdcb9bd
ecc304a
748b590
60b26b0
28beca0
07afc37
cb47618
f302ca8
ad93826
7f23bb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| //go:build goexperiment.jsonv2 | ||
techknowlogick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
techknowlogick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| package json | ||
techknowlogick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| import ( | ||
| jsonv2 "encoding/json/v2" | ||
| "io" | ||
| ) | ||
|
|
||
| // isJSONv2Available returns true when JSON v2 is available (compiled with GOEXPERIMENT=jsonv2) | ||
| func isJSONv2Available() bool { | ||
| return true | ||
| } | ||
|
|
||
| // marshalV2 uses JSON v2 marshal with v1 compatibility options | ||
| func marshalV2(v any) ([]byte, error) { | ||
| opts := jsonv2.JoinOptions( | ||
| jsonv2.MatchCaseInsensitiveNames(true), | ||
| jsonv2.FormatNilSliceAsNull(true), | ||
| jsonv2.FormatNilMapAsNull(true), | ||
| ) | ||
| return jsonv2.Marshal(v, opts) | ||
| } | ||
|
|
||
| // unmarshalV2 uses JSON v2 unmarshal with v1 compatibility options | ||
| func unmarshalV2(data []byte, v any) error { | ||
| opts := jsonv2.JoinOptions( | ||
| jsonv2.MatchCaseInsensitiveNames(true), | ||
| ) | ||
| return jsonv2.Unmarshal(data, v, opts) | ||
| } | ||
|
|
||
| // encoderV2 wraps JSON v2 streaming encoder | ||
| type encoderV2 struct { | ||
| writer io.Writer | ||
| opts jsonv2.Options | ||
| } | ||
|
|
||
| func (e *encoderV2) Encode(v any) error { | ||
| return jsonv2.MarshalWrite(e.writer, v, e.opts) | ||
| } | ||
|
|
||
| // newEncoderV2 creates a new JSON v2 streaming encoder | ||
| func newEncoderV2(writer io.Writer) Encoder { | ||
| opts := jsonv2.JoinOptions( | ||
| jsonv2.MatchCaseInsensitiveNames(true), | ||
| jsonv2.FormatNilSliceAsNull(true), | ||
| jsonv2.FormatNilMapAsNull(true), | ||
| ) | ||
| return &encoderV2{writer: writer, opts: opts} | ||
| } | ||
|
|
||
| // decoderV2 wraps JSON v2 streaming decoder | ||
| type decoderV2 struct { | ||
| reader io.Reader | ||
| opts jsonv2.Options | ||
| } | ||
|
|
||
| func (d *decoderV2) Decode(v any) error { | ||
| return jsonv2.UnmarshalRead(d.reader, v, d.opts) | ||
| } | ||
|
|
||
| // newDecoderV2 creates a new JSON v2 streaming decoder | ||
| func newDecoderV2(reader io.Reader) Decoder { | ||
| opts := jsonv2.JoinOptions( | ||
| jsonv2.MatchCaseInsensitiveNames(true), | ||
| ) | ||
| return &decoderV2{reader: reader, opts: opts} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //go:build !goexperiment.jsonv2 | ||
techknowlogick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
techknowlogick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
techknowlogick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| package json | ||
|
Check failure on line 6 in modules/json/jsonv2_fallback.go
|
||
techknowlogick marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import "io" | ||
|
|
||
| // isJSONv2Available returns false when JSON v2 is not available (not compiled with GOEXPERIMENT=jsonv2) | ||
| func isJSONv2Available() bool { | ||
| return false | ||
| } | ||
|
|
||
| // marshalV2 fallback - should not be called when JSON v2 is not available | ||
| func marshalV2(v any) ([]byte, error) { | ||
| panic("JSON v2 not available - build with GOEXPERIMENT=jsonv2") | ||
| } | ||
|
|
||
| // unmarshalV2 fallback - should not be called when JSON v2 is not available | ||
| func unmarshalV2(data []byte, v any) error { | ||
| panic("JSON v2 not available - build with GOEXPERIMENT=jsonv2") | ||
| } | ||
|
|
||
| // newEncoderV2 fallback - should not be called when JSON v2 is not available | ||
| func newEncoderV2(writer io.Writer) Encoder { | ||
| panic("JSON v2 not available - build with GOEXPERIMENT=jsonv2") | ||
| } | ||
|
|
||
| // newDecoderV2 fallback - should not be called when JSON v2 is not available | ||
| func newDecoderV2(reader io.Reader) Decoder { | ||
| panic("JSON v2 not available - build with GOEXPERIMENT=jsonv2") | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.