fix: not using MarshalAll for output jsonobject (#13156)

Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
Jian Qiu
2022-01-10 09:53:30 +08:00
committed by GitHub
parent a8f3d54259
commit d1a270baaa
4 changed files with 18 additions and 6 deletions
+15 -3
View File
@@ -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()
+1 -1
View File
@@ -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 {
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
// }