JAX-RS:即使传递了一些不正确的数据类型,也会传递@DefaultValue?

时间:2013-02-12 23:27:15

标签: java rest jax-rs

我的端点看起来像

 @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Response getVariables(@QueryParam("_activeonly") @DefaultValue("no") @Nonnull final Active active) {
        switch (active) {
            case yes:
                return Response.ok(VariablePresentation.getPresentationVariables(variableManager.getActiveVariables())).build();
            case no:
                return Response.ok(VariablePresentation.getPresentationVariables(variableManager.getVariables())).build();
        }
        throw new WebApplicationException(Response.Status.BAD_REQUEST);
    }

Active

的位置
  public enum Active {
        yes,
        no;
    }

我将其测试为

   @Test
    public void testGetAllVariablesUnknownActionFail() throws Exception {
        final ClientRequest clientRequest = new ClientRequest("http://localhost:9090/market/rest/variables?_activeonly=unknown");
        final ClientResponse<String> clientResponse = clientRequest.get(String.class);
        assertEquals(400, clientResponse.getStatus());
    }

虽然我期待HTTP 400,但我收到HTTP 200

: expected:<400> but was:<200>

这是否意味着如果我传入了一些未映射到枚举的错误值,则使用@DefaultValue

0 个答案:

没有答案