Java JAX-RS:即使传递了一些不正确的数据类型,@DefaultValue也会被传递吗?
我的端点看起来像Java JAX-RS:即使传递了一些不正确的数据类型,@DefaultValue也会被传递吗?,java,rest,jax-rs,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.o
@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);
}
其中处于活动状态
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());
}
这是否意味着如果我传入了一些不正确的值,而这些值没有映射到enum,就会使用
@DefaultValue
?我会在端点内输入一个断点或打印一个活动变量,然后查看得到的结果。我原以为序列化会有问题。
: expected:<400> but was:<200>