Skip to content

Custom converter is not used for enum list query parameter  #1598

@ltparis2018

Description

@ltparis2018

We have a REST endpoint that uses a query parameter being a list of enum values. The values of the corresponding enum type have labels that should be used in the url. Here is an example in Kotlin:

enum class MyEnum(val label: String) {
    VALUE_1("value1"),
    VALUE_2("value2"),
    VALUE_3("value3");
}

We added a custom converter to Spring's FormatterRegistry that converts a value of MyEnum to a string using the label.

Conversion works fine for a query parameter being a single value. Unfortunately, for collections converter is not invoked and our MyEnum values are converted to their names. We get something like that:

http://myserver.com/path/file.html?param=VALUE_1&param=VALUE_2

instead of

http://myserver.com/path/file.html?param=value1&param=value2

We think the problem lies in bindRequestParameters() method of org.springframework.hateoas.server.core.WebHandler. In case of parameter values being a collection the conversion service is not used like it is for single values.

Our current workaround for this is to overwrite the toString() method of the Enum to get the label.

We currently use HATEOAS library version 1.3.2. We checked out milestone version 1.4.0-M2 but the problem is still there.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions