I'm having problems with omitempty
and empty values. Please see this playground example. I have a value which I don't want to be ignored during marshal in case of value ""
. This explicitly means that I want to clear the value and therefore I want to have marshalled result:
{"cf_objectType":"Product","cf_isLocked":"No","cf_ErrorMessage":""}
Now I tried the pointer-to-string approach here, but for some reason I don't like this. Are there any alternatives known? For example, why don't we have a tag (just like omitempty
) like omitnull
or something?
EDIT
To clarify, see below
m := Metadata{
ObjectType: "Product",
Locked: "No",
ErrorMessage: "",
}
I want the result of the marshal function on this struct to be:
{
"cf_objectType":"Product",
"cf_isLocked":"No",
"cf_ErrorMessage":""
}
AND
m := Metadata{
ObjectType: "Product",
Locked: "No",
}
result shoulde be:
{
"cf_objectType":"Product",
"cf_isLocked":"No",
}