go-jsonschema icon indicating copy to clipboard operation
go-jsonschema copied to clipboard

special case objects with only string values

Open codefromthecrypt opened this issue 3 years ago • 0 comments

When unmarshalling, I think we can special-case when the json represented only includes string fields.

Instead of

func (j *Download) UnmarshalJSON(b []byte) error {
	var raw map[string]interface{}
	if err := json.Unmarshal(b, &raw); err != nil {
		return err
	}
	if v, ok := raw["architecture"]; !ok || v == nil {

this

func (j *Download) UnmarshalJSON(b []byte) error {
	var raw map[string]string
	if err := json.Unmarshal(b, &raw); err != nil {
		return err
	}
	if v, ok := raw["architecture"]; !ok || v == "" {

codefromthecrypt avatar May 22 '21 06:05 codefromthecrypt