migrate direct jsoniter usage to encoding/json#107
Conversation
chenhengqi
left a comment
There was a problem hiding this comment.
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
|
Addressed based on feedback and aligned this PR with CONTRIBUTING guidance.
Targeted validation performed:
Note on failing tests:
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
|
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) |
There was a problem hiding this comment.
Note that json.Marshal() returns a byte slice instead of string.
There was a problem hiding this comment.
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.
chenhengqi
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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{}
Touches CubeMaster, Cubelet, cubelog, Makefile, Docker builder, and network-agent tests. Assisted-by: Cursor:GPT-5.1 Co-authored-by: Cursor <cursoragent@cursor.com>
Summary
github.com/json-iterator/gousage in.gosource withencoding/jsonValidation
git grep -nE 'github.com/json-iterator/go|jsoniter\.' -- '*.go'returns no matchespkg/store/cubeboxdelete-container test failures were reproduced on cleanorigin/masterbaseline (pre-existing)