This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new 53c1f9980 fix(rmqctl): restore numeric types before YAML encoding
(#6057)
53c1f9980 is described below
commit 53c1f998031586e4387d50b71e7af9f1f5c98d38
Author: lizhimins <[email protected]>
AuthorDate: Sat Oct 10 14:28:18 2026 +0800
fix(rmqctl): restore numeric types before YAML encoding (#6057)
---
rmqctl/internal/output/output.go | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/rmqctl/internal/output/output.go b/rmqctl/internal/output/output.go
index a00caf90d..90ec62bb6 100644
--- a/rmqctl/internal/output/output.go
+++ b/rmqctl/internal/output/output.go
@@ -51,13 +51,45 @@ func JSON(w io.Writer, value any) error {
func YAML(w io.Writer, value any) error {
encoder := yaml.NewEncoder(w)
encoder.SetIndent(2)
- if err := encoder.Encode(value); err != nil {
+ if err := encoder.Encode(restoreNumbers(value)); err != nil {
_ = encoder.Close()
return err
}
return encoder.Close()
}
+// restoreNumbers turns json.Number values back into numbers. The studio
client decodes with
+// UseNumber() so integer literals survive untouched, and json.Number is a
string type: yaml.v3
+// would emit it quoted, so `size: 3` came out as `size: "3"` and the YAML no
longer round-tripped
+// to the payload the server sent. The JSON path needs no such step because
encoding/json marshals
+// json.Number as a bare literal.
+func restoreNumbers(value any) any {
+ switch typed := value.(type) {
+ case json.Number:
+ if i, err := typed.Int64(); err == nil {
+ return i
+ }
+ if f, err := typed.Float64(); err == nil {
+ return f
+ }
+ return typed.String()
+ case map[string]any:
+ restored := make(map[string]any, len(typed))
+ for key, entry := range typed {
+ restored[key] = restoreNumbers(entry)
+ }
+ return restored
+ case []any:
+ restored := make([]any, len(typed))
+ for i, entry := range typed {
+ restored[i] = restoreNumbers(entry)
+ }
+ return restored
+ default:
+ return value
+ }
+}
+
func Structured(w io.Writer, format string, value any) error {
switch format {
case formatJSON: