- 
          
- 
        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
          
     Merged
      
      
    
  
     Merged
                    Changes from 3 commits
      Commits
    
    
            Show all changes
          
          
            35 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c5f251b
              
                use experimental go json v2 library
              
              
                 cb16b33
              
                Merge branch 'main' into jsonv2
              
              
                techknowlogick abc734c
              
                Update go.mod
              
              
                techknowlogick f9c8805
              
                Update jsonv2.go
              
              
                techknowlogick 9d83440
              
                Update jsonv2.go
              
              
                techknowlogick 31492c1
              
                Update jsonv2.go
              
              
                techknowlogick 7b0832c
              
                Update jsonv2.go
              
              
                techknowlogick fe51938
              
                Update jsonv2_fallback.go
              
              
                techknowlogick 29d1770
              
                Update jsonv2_fallback.go
              
              
                techknowlogick 3c3f77f
              
                Update jsonv2_fallback.go
              
              
                techknowlogick ce4107d
              
                Merge branch 'main' into jsonv2
              
              
                techknowlogick b8fb94d
              
                Update jsonv2_fallback.go
              
              
                techknowlogick c748ca8
              
                Update jsonv2_fallback.go
              
              
                techknowlogick f9d91f2
              
                Merge branch 'main' into jsonv2
              
              
                techknowlogick 7fec838
              
                Update Go version from 1.24.6 to 1.25.0
              
              
                techknowlogick 3c6d690
              
                bump go.mod
              
              
                techknowlogick b3969be
              
                use fixed go-swagger version
              
              
                techknowlogick ba43047
              
                Merge branch 'main' into jsonv2
              
              
                techknowlogick 94d537c
              
                Update GOEXPERIMENT to use jsonv2 by default
              
              
                techknowlogick 82b2d97
              
                fix lint
              
              
                techknowlogick 502b4fb
              
                clean up modernizer fixes
              
              
                techknowlogick d4b1e10
              
                try to fix lint
              
              
                techknowlogick 8f3b218
              
                try to use go1.25 waitgroup logic
              
              
                techknowlogick 34af20c
              
                fixup test fails
              
              
                techknowlogick a65bff4
              
                Merge remote-tracking branch 'upstream/main' into jsonv2
              
              
                 cdcb9bd
              
                adjust jsonv2 output to become similar to v1
              
              
                 ecc304a
              
                resolve vagrant test failure
              
              
                 748b590
              
                the security check has a panic when using the experimental go library
              
              
                 60b26b0
              
                resolve panic in assetfs parsing of embeded data
              
              
                 28beca0
              
                Merge branch 'main' into jsonv2
              
              
                wxiaoguang 07afc37
              
                fix
              
              
                wxiaoguang cb47618
              
                fix
              
              
                wxiaoguang f302ca8
              
                fix
              
              
                wxiaoguang ad93826
              
                fine tune
              
              
                wxiaoguang 7f23bb9
              
                Merge branch 'main' into jsonv2
              
              
                wxiaoguang File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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 | ||
| // 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} | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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 | ||
|         
                  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") | ||
| } | ||
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.