API: Improve MarshalToJson() in common/reflect/marshal.go (#3655)

* Serialize enum to string in MarshalToJson().

* MarshalToJson() respect json tags.

* Add insertTypeInfo parameter to MarshalToJson().

* Omit empty string in MarshalToJson().

* Serialize PortList to string in MarshalToJson().

---------

Co-authored-by: nobody <nobody@nowhere.mars>
This commit is contained in:
nobody 2024-08-08 22:35:46 +08:00 committed by GitHub
parent 4a1c0d7124
commit ac628a9427
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 148 additions and 41 deletions

View file

@ -17,7 +17,7 @@ func MergeConfigFromFiles(files []string, formats []string) (string, error) {
return "", err
}
if j, ok := creflect.MarshalToJson(c); ok {
if j, ok := creflect.MarshalToJson(c, true); ok {
return j, nil
}
return "", errors.New("marshal to json failed.").AtError()