mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-08-31 01:35:56 +08:00
fix: not using MarshalAll for output jsonobject (#13156)
Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -178,6 +178,10 @@ func (p *param) convert() (reflect.Value, error) {
|
||||
}
|
||||
|
||||
func ValueToJSONObject(out reflect.Value) jsonutils.JSONObject {
|
||||
return _valueToJSONObject(out, false)
|
||||
}
|
||||
|
||||
func _valueToJSONObject(out reflect.Value, allFields bool) jsonutils.JSONObject {
|
||||
if gotypes.IsNil(out.Interface()) {
|
||||
return nil
|
||||
}
|
||||
@@ -185,11 +189,19 @@ func ValueToJSONObject(out reflect.Value) jsonutils.JSONObject {
|
||||
if obj, ok := isJSONObject(out); ok {
|
||||
return obj
|
||||
}
|
||||
return jsonutils.MarshalAll(out.Interface())
|
||||
if allFields {
|
||||
return jsonutils.MarshalAll(out.Interface())
|
||||
} else {
|
||||
return jsonutils.Marshal(out.Interface())
|
||||
}
|
||||
}
|
||||
|
||||
func ValueToJSONDict(out reflect.Value) *jsonutils.JSONDict {
|
||||
jsonObj := ValueToJSONObject(out)
|
||||
return _valueToJSONDict(out, false)
|
||||
}
|
||||
|
||||
func _valueToJSONDict(out reflect.Value, allFields bool) *jsonutils.JSONDict {
|
||||
jsonObj := _valueToJSONObject(out, allFields)
|
||||
if jsonObj == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -205,7 +217,7 @@ func ValueToError(out reflect.Value) error {
|
||||
}
|
||||
|
||||
func mergeInputOutputData(input *jsonutils.JSONDict, resVal reflect.Value) *jsonutils.JSONDict {
|
||||
output := ValueToJSONDict(resVal)
|
||||
output := _valueToJSONDict(resVal, true)
|
||||
// preserve the input info not returned by caller
|
||||
ret := input.Copy()
|
||||
jsonMap, _ := output.GetMap()
|
||||
|
||||
@@ -40,7 +40,7 @@ func Test_valueToJSONObject(t *testing.T) {
|
||||
{
|
||||
name: "struct2json",
|
||||
args: &api.ServerRebuildRootInput{Image: "image"},
|
||||
want: jsonutils.MarshalAll(api.ServerRebuildRootInput{Image: "image"}),
|
||||
want: jsonutils.Marshal(api.ServerRebuildRootInput{Image: "image"}),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -151,7 +151,7 @@ func (self *EipDissociateTask) OnInit(ctx context.Context, obj db.IStandaloneMod
|
||||
}
|
||||
}
|
||||
default:
|
||||
errs = append(errs, errors.Wrapf(httperrors.ErrNotSupported, "not supported type", eip.AssociateType))
|
||||
errs = append(errs, errors.Wrapf(httperrors.ErrNotSupported, "not supported type %s", eip.AssociateType))
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
err := errors.NewAggregate(errs)
|
||||
|
||||
@@ -807,7 +807,7 @@ func (s *SGuestResumeTask) taskFailed(reason string) {
|
||||
}
|
||||
|
||||
func (s *SGuestResumeTask) onGetBlockInfo(blocks []monitor.QemuBlock) {
|
||||
log.Debugf("onGetBlockInfo %s", blocks)
|
||||
log.Debugf("onGetBlockInfo %v", blocks)
|
||||
// for _, drv := range results.GetArray() {
|
||||
// // encryption not work
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user