Skip to content

One-element array in a query parameter not parsed correctly #99

@mz8i

Description

@mz8i

When a query parameter is an Array, but the query contains just one element
(for example /path?words=foo as opposed to /path?words=foo&words=bar) then at run-time the parameter passed to the controller is actually a string, not a one-element array.

In my controller, I solved it by code that feels like it could be included in the library code which parses the parameters?

@GET
@Path('endpoint')
public endpoint(@QueryParam('words') words: string[]): void {
    let wordsArray = words;
    if (typeof wordsArray === 'string') {
        wordsArray = [wordsArray];
    }

    // do something with wordsArray
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions