You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Go Structure generated for the above JSON schema is -
// Code generated by github.com/atombender/go-jsonschema, DO NOT EDIT.package main
typeUpdateObjectstruct {
// FieldValues corresponds to the JSON schema field "fieldValues".FieldValues []string`json:"fieldValues,omitempty" yaml:"fieldValues,omitempty" mapstructure:"fieldValues,omitempty"`
}
If I set an empty slice in FieldValues, the json marshaler omits this field from the marshaled data. It is because JSON Marshaler considers an empty slice as an empty value, rather than a nil slice as an empty value.
I want a way where I can indicate in the marshaled JSON if the FieldValues was set but empty. I can achieve this by making the FieldValues as *[]string and then setting a pointer to empty slice in FieldValues, but I don't see any way in the tool using which I can specify something in the schema for the fieldValues or in the options of the tool that I want the array to be generated as a pointer to a slice. Is there any way?
Also, I don't want to make this field required because if the fieldValues is not set, I don't want to marshal anything in the marshaled JSON.
The text was updated successfully, but these errors were encountered:
I'm using the go-jsonschema tool to generate the Go Structures and then use these Go Structures to marshal the values I'd set to JSON.
I've defined the following JSON schema -
The Go Structure generated for the above JSON schema is -
If I set an empty slice in
FieldValues
, the json marshaler omits this field from the marshaled data. It is because JSON Marshaler considers an empty slice as an empty value, rather than a nil slice as an empty value.I want a way where I can indicate in the marshaled JSON if the
FieldValues
was set but empty. I can achieve this by making theFieldValues
as*[]string
and then setting a pointer to empty slice inFieldValues
, but I don't see any way in the tool using which I can specify something in the schema for thefieldValues
or in the options of the tool that I want the array to be generated as a pointer to a slice. Is there any way?Also, I don't want to make this field required because if the
fieldValues
is not set, I don't want to marshal anything in the marshaled JSON.The text was updated successfully, but these errors were encountered: