title: Check for specific enum values in RequestParam Springboot
body: <p>I have a Spring Boot API with some controllers that use an enum as a RequestParam. This all works fine. If I use a value that is not in the enum, I will get an error. However, I can't seem to find anywhere if it is possible to validate if the requestParam is part of a subset of the enum.</p>
  <p>The enum looks something like this:</p>
  <pre><code>public enum Type {
      @JsonProperty(&quot;een&quot;)
      ONE(&quot;een&quot;),
  
      @JsonProperty(&quot;twee&quot;)
      TWO(&quot;twee&quot;),
  
      @JsonProperty(&quot;drie&quot;)
      THREE(&quot;drie&quot;);
  
      private final String value;
  
      private static final Map&lt;String, Type&gt; lookup = new HashMap&lt;String, Type&gt;();
  
      static {
          for (Type type : Type.values()) {
              lookup.put(type.value, type);
          }
      }
  
      private Type(String value) {
          this.value = value;
      }
  
      public String getValue() {
          return this.value;
      }
  
      public static Type get(String value) {
          return lookup.get(value);
      }
  
      @Override
      public String toString() {
          return this.value;
      }
  }
  </code></pre>
  <p>I have created a org.springframework.core.convert.converter.Converter in order to use the enum like this (value with different enum name).</p>
  <p>The endpoints look something like this:</p>
  <pre><code>@GetMapping(&quot;/my-endpoint&quot;)
      public ResponseEntity&lt;Set&lt;Item&gt;&gt; getItems(
          @RequestParam Type type
      ) {
          &lt;... etc&gt;
      return new ResponseEntity&lt;Set&lt;Item&gt;&gt;(items, HttpStatus.OK);
  }
  </code></pre>
  <p>So for example I would like to validate for one of my endpoints if the RequestParam has value &quot;een&quot; or &quot;twee&quot; and should return a bad request if it has value &quot;drie&quot;. And for another endpoint I would like to validate if the RequestParam has value &quot;twee&quot; or &quot;drie&quot;. This is a simplified example, in reality I have a lot more options in the enum and a lot mare endpoints that use all or a subset of the enum.
  I know I could create different enums with the subsets, but because the they are used often in different subsets each time, this is not really an option.</p>
  <p>Is there any other way to do this?</p>