Skip to content

migrate direct jsoniter usage to encoding/json#107

Open
dkshitij29 wants to merge 9 commits into
TencentCloud:masterfrom
dkshitij29:master
Open

migrate direct jsoniter usage to encoding/json#107
dkshitij29 wants to merge 9 commits into
TencentCloud:masterfrom
dkshitij29:master

Conversation

@dkshitij29
Copy link
Copy Markdown

Summary

  • Replace direct github.com/json-iterator/go usage in .go source with encoding/json
  • Update marshal/unmarshal callsites and byte-to-string boundaries where required
  • Keep behavior equivalent while removing jsoniter-specific source usage

Validation

  • git grep -nE 'github.com/json-iterator/go|jsoniter\.' -- '*.go' returns no matches
  • Linux container compile checks passed for key changed packages
  • pkg/store/cubebox delete-container test failures were reproduced on clean origin/master baseline (pre-existing)

Copy link
Copy Markdown
Collaborator

@chenhengqi chenhengqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read and follow our contribution guide.

Replace direct jsoniter usage in Go sources with encoding/json and adjust call sites for equivalent behavior while keeping module state buildable.

Autonomously-by: Codex:5.3
Made-with: Cursor
@dkshitij29
Copy link
Copy Markdown
Author

dkshitij29 commented Apr 28, 2026

Addressed based on feedback and aligned this PR with CONTRIBUTING guidance.

  • Source migration is complete: direct github.com/json-iterator/go / jsoniter. usage in Go sources has been replaced with encoding/json calls (no alias indirection).
  • All touched Go files were formatted with gofmt.
  • Commit history was cleaned to remove intermediate/noise work so the branch now contains a single focused migration commit.

Targeted validation performed:

  • git grep -nE 'github.com/json-iterator/go|jsoniter\.' -- '*.go' -> no matches.
  • Linux container compile checks completed successfully for key changed packages.

Note on failing tests:

  • Cubelet/pkg/store/cubebox failures in TestStoreDeleteContainer* were reproduced from clean origin/master in a separate worktree and Linux container, indicating this behavior is pre-existing and not introduced by this migration.
  • Some storage tests can fail in unprivileged containers due to mount permission limits (Operation not permitted) unless a privileged runtime is used.

Please let me know if you want this split further into component-scoped commits.

Replace direct jsoniter usage in CubeMaster with encoding/json to align serialization behavior and remove dependency-specific call patterns.

Autonomously-by: Codex:5.3
Made-with: Cursor
Replace direct jsoniter usage in Cubelet with encoding/json and update marshaling/unmarshaling call sites for compatibility.

Autonomously-by: Codex:5.3
Made-with: Cursor
Use encoding/json in cubelog to remove direct jsoniter imports and keep logging payload serialization consistent.

Autonomously-by: Codex:5.3
Made-with: Cursor
Update module metadata related to the json migration so network-agent remains consistent with repository-wide serialization changes.

Autonomously-by: Codex:5.3
Made-with: Cursor
@dkshitij29 dkshitij29 deleted the branch TencentCloud:master April 29, 2026 00:20
@dkshitij29 dkshitij29 closed this Apr 29, 2026
@dkshitij29 dkshitij29 deleted the master branch April 29, 2026 00:20
@dkshitij29 dkshitij29 restored the master branch April 29, 2026 00:20
@dkshitij29 dkshitij29 reopened this Apr 29, 2026
@dkshitij29
Copy link
Copy Markdown
Author

Reopened after branch ref restore/rename issue. Latest migration commits are unchanged; requesting re-review.

}
respStr, err := jsoniter.MarshalToString(rsp)

respStr, err := json.Marshal(rsp)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that json.Marshal() returns a byte slice instead of string.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, Will need to work on full pr again to check if there are any other mistakes.

I have declared a new valriable called "respBytes".
respBytes, err := json.Marshal(rsp)
//error handling
respStr := string(respBytes) // converting it back to str.

Hope that works. New to go. Typical beginner mistakes.

Copy link
Copy Markdown
Collaborator

@chenhengqi chenhengqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure you review the code that AI generated before open a PR. Thanks.

for k, v := range all {
bf := &createInfo{}
err = jsoniter.ConfigFastest.Unmarshal(v, bf)
err = json.Unmarshal(v, bf)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @chenhengqi.
Had a query on this the old alias call had jsoniter.ConfigFastest.Unmarshal(v, bf) -> json.Unmarshal(v, bf).

Will we run into any performance or memory allocation issues with increased object sizes in this specific path? Based on docs, ConfigFastest skips strict validations to prioritize speed, so I want to ensure the standard library will still meet our throughput requirements for these payloads.

})

b, err := jsoniter.MarshalToString(toAppendDevices)
b, err := json.Marshal(toAppendDevices)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String conversion not required here:
there is a inline string conversion method called in the log entry. below the err handing.
logEntry = logEntry.WithField(API_UPDATE_ACTION_DATA_KEY, string(b))

StartTime contextKey = "startTime"
)

var FastestJsoniter = jsoniter.Config{
Copy link
Copy Markdown
Author

@dkshitij29 dkshitij29 May 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a custom struct block as a replacement here(AI suggested). @chenhengqi do you have any better suggestions or this is fine, wanted your feedback?
func (stdJSONTool) Marshal(v interface{}) ([]byte, error) {
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
if err := enc.Encode(v); err != nil {
return nil, err
}
out := b.Bytes()
if n := len(out); n > 0 && out[n-1] == '\n' {
out = out[:n-1]
}
return out, nil
}

func (stdJSONTool) Unmarshal(data []byte, v interface{}) error {
dec := json.NewDecoder(bytes.NewReader(data))
dec.UseNumber()
return dec.Decode(v)
}

var FastestJsoniter = stdJSONTool{}

dkshitij29 and others added 3 commits May 3, 2026 16:46
Touches CubeMaster, Cubelet, cubelog, Makefile, Docker builder, and network-agent tests.

Assisted-by: Cursor:GPT-5.1
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants