Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConversionFailedException: When accessing v3/api-docs #1097

Closed
mychalvlcek opened this issue Mar 9, 2021 · 1 comment
Closed

ConversionFailedException: When accessing v3/api-docs #1097

mychalvlcek opened this issue Mar 9, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@mychalvlcek
Copy link

Describe the bug
When a want to access v3/api-docs, i got following exception

ConversionFailedException: Failed to convert from type [java.lang.String] to type [xxx.xxx.OrderState] for value 'finished'; nested exception is java.lang.IllegalArgumentException: No enum constant xxx.xxx.OrderState.finished

I have following controller where is:

  • enum as request parameter (with default value),
  • enum has custom mapper dataBinder.registerCustomEditor(OrderState.class, new OrderStateMapper());
@RestController
@RequiredArgsConstructor
class TestController {

    @InitBinder
    public void initBinder(WebDataBinder dataBinder) {
        dataBinder.registerCustomEditor(OrderState.class, new OrderStateMapper());
    }
    
    @GetMapping(value = {"/orders"})
    public Object method(
            @RequestParam(value = "state", defaultValue = "finished") OrderState orderState) {
    }
}

@Getter
@RequiredArgsConstructor
public enum OrderState {
    FINISHED("finished"),
    NEW("new"),
    
    private final String value;
}
public class OrderStateMapper extends PropertyEditorSupport {

    @Override
    public void setAsText(String text) {
        setValue(
                Arrays.stream(OrderState.class.getEnumConstants())
                        .filter(e -> e.getValue().equals(text))
                        .findFirst()
                        .orElseThrow(() -> new MethodArgumentTypeMismatchException(
                                text, OrderState.class, "orderState", null, null)));
    }
}

Expected behavior

  • generator should handle enum params with default values (with custom mapper/binder)
@bnasslahsen
Copy link
Contributor

@mychalvlcek,

This will be fixed for the next release.
You have a sample on the test: 60e0512

This was referenced Mar 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants