0

I want to restrict REST service parameters by an enum as follows:

public class enum {
    TEST;
}

@RestController
public class MyRest {
   @RequestMapping(method = RequestMethod.GET)
   public Object content(@RequestParam value="list" required=false) List<MyEnum> list) {
    Sysout(list);
  }
}

This works great if I call: /app?list=TEST.

But when invoking /app?list=test (lowercase letters) the rest services does not respond.

How can I eg provide custom values for the enum types to be accepted?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • 1
    Solution was to add the following into the rest service controller: `@InitBinder protected void initBinder(WebDataBinder binder) { binder.registerCustomEditor(MyEnum.class, new EnumConverter(MyEnum.class));}` – membersound Jan 27 '15 at 10:32

1 Answers1

-6

I am not sure about the way you are doing it. But we can do it in another way.

public class enum {
  TEST(1, "TEST");
}

@RestController
public class MyRest {
  @RequestMapping(method = RequestMethod.GET)
  public Object content(@RequestParam value="list" required=false) List<Integer> list) {
    for(Integer int: list)
    sysout(enum.get(int));
  }
}

You can pass in a list of integers and map the enum against these int values. Passing a list of integers seems cleaner to me.

Thanks!!

Nihal Sharma
  • 2,397
  • 11
  • 41
  • 57