title: Specifying an optional parameter with a default value for restful web service
body: <p>I'm trying to create a webservice that returns an int. It should also have an optional parameter - this fails.</p>
  
  <p>This works:</p>
  
  <pre><code>package foo;
  
  import java.util.Map;
  import java.util.TreeMap;
  
  import javax.ws.rs.DefaultValue;
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.QueryParam;
  import javax.ws.rs.core.MediaType;
  
  @Path("/euler")
  public class Euler1 {
  
      @GET
      @Path("/getmultiples")
      @Produces(MediaType.APPLICATION_JSON)
      public static Map&lt;String, Integer&gt; getMultiples() {
          int sum = 0;
          int limit = 1000;
          for (int i = 0; i &lt; limit; i += 3) {
              sum += i;
          }
          for (int i = 0; i &lt; limit; i += 5) {
              if (i % 3 != 0) {
                  sum += i;
              }
          }
          final Map&lt;String, Integer&gt; result = new TreeMap&lt;&gt;();
          result.put("Sum", sum);
          return result;
      }
  }
  </code></pre>
  
  <p>If I call it like <code>curl http://localhost:8080/foo/rest/euler/getmultiples</code> I get <code>{"Sum":233168}</code>.</p>
  
  <hr>
  
  <p>But the limit should be an optional parameter. So I change the method signature to</p>
  
  <pre><code>public static Map&lt;String, Integer&gt; getMultiples(
     @DefaultValue("1000") @QueryParam(value = "limit") int limit)
  </code></pre>
  
  <p>But then the previous returns nothing, and the server (Wildfly 8) logs</p>
  
  <pre><code>15:07:08,889 ERROR [io.undertow.request] (default task-3) UT005023: Exception handling request to /foo/rest/euler/getmultiples: java.lang.ArrayIndexOutOfBoundsException: 0
      at org.jboss.resteasy.plugins.validation.GeneralValidatorImpl.parametersResolveToSameTypes(GeneralValidatorImpl.java:515) [resteasy-validator-provider-11-3.0.10.Final.jar:]
      at org.jboss.resteasy.plugins.validation.GeneralValidatorImpl.overrides(GeneralValidatorImpl.java:486) [resteasy-validator-provider-11-3.0.10.Final.jar:]
      at org.jboss.resteasy.plugins.validation.GeneralValidatorImpl.getSuperMethod(GeneralValidatorImpl.java:444) [resteasy-validator-provider-11-3.0.10.Final.jar:]
      at org.jboss.resteasy.plugins.validation.GeneralValidatorImpl.getExecutableTypesOnMethodInHierarchy(GeneralValidatorImpl.java:335) [resteasy-validator-provider-11-3.0.10.Final.jar:]
      at org.jboss.resteasy.plugins.validation.GeneralValidatorImpl.isMethodValidatable(GeneralValidatorImpl.java:265) [resteasy-validator-provider-11-3.0.10.Final.jar:]
  </code></pre>
  
  <p>Here's the web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
      version="3.1"&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;javax.ws.rs.core.Application&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The archetype used is the latest version of <code>com.airhacks:javaee7-essentials-archetype</code>.</p>
  
  <p>Here's the <code>pom.xml</code>:</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;de.oneiros&lt;/groupId&gt;
      &lt;artifactId&gt;webservice-ee7&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax&lt;/groupId&gt;
              &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
              &lt;version&gt;7.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;finalName&gt;webservice-ee7&lt;/finalName&gt;
      &lt;/build&gt;
      &lt;properties&gt;
          &lt;maven.compiler.source&gt;1.8&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.8&lt;/maven.compiler.target&gt;
          &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
      &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>How can I pass an optional parameter to my method?</p>