Skip to content

unexpected deepObject encoding of nil map #160

Description

@SKalt

I'm trying to use the zero value of a map as a tag-map query parameter type. This is producing an unexpected encoding, tags[]=null -- if there aren't any tags in the tag-map, no tags[] query parameters should be produced. Here's a reproduction case:

var nilTags map[string]string
result, _ := runtime.StyleParamWithOptions(
	"deepObject", true, "tags", nilTags,
	runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery},
)
fmt.Println("unexpected", result) // "tags[]=null"

(https://go.dev/play/p/Xa-sVpopeE_K)

This behavior is due to the json-marshalling-and-unmarshalling step in deepobject.go's MarshalDeepObject function, which obscures that the input is a nil map, not another type of nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions