泽西岛ValidationException消息并不总是相同

时间:2018-10-30 12:49:54

标签: api validation jersey

在我正在使用的API中,我具有以下定义:

@PUT
@Path("/{messageTypeId}")
@Consumes({ "application/json" })
@Produces({ "application/json" })
@ApiOperation(value = "Amend the Message Type.", notes = "Amend the Message Type.", tags={  })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "Successful response.", response = Void.class),
    @ApiResponse(code = 400, message = "Bad Request.", response = Problem.class),
    @ApiResponse(code = 404, message = "Not Found.", response = Problem.class),
    @ApiResponse(code = 500, message = "Internal Server Error.", response = Problem.class),
    @ApiResponse(code = 503, message = "Service Unavailable.", response = Problem.class) })
void amendMessageType_(@PathParam("messageTypeId") @Size(max=255) @ApiParam("Message Type Unique Identifier") String messageTypeId,@Valid MessageTypeAmendBody messageTypeBody) throws Exception;

当ValidationException发生时,有一个ExceptionMapper来捕获并格式化JSON错误。似乎映射器有时会收到这样的消息:

arg0 is not correct, must be between 0 and 255

有时

messageTypeId is not correct, must be between 0 and 255

当我从IntelliJ(我得到第一个)和Maven(第二个)运行单元测试时,或者当我运行应用程序(一个或另一个)时,情况就是这样。 / p>

谢谢!

1 个答案:

答案 0 :(得分:0)

要解决此问题,我必须添加一个编译标志:

const postcodeToBeConverted = "BB80LD";

const conversionTable = {
  BB80LD: [-2.1702448, 53.85482989]
};

// Simplified version of MongoDB query
const postcodeToGeo = new Promise(resolve => {
  return resolve(lookup.BB80LD);
});

// 1.1 Renders incorrectly
// console.log(postcodeToGeo.then(res => res));

// 1.2 Renders correctly
// postcodeToGeo.then(res => console.log(res));

// Injecting value into another object
const masterQuery = {};

// How can inject the Geo value rendered by function 1.2 ?
masterQuery.postcode = postcodeToGeo.then(res => res);

/* 
 * Desired output => 
 *    masterQuery: {
 *        postcode: [-2.1702448,53.85482989]
 *    }
 *
 * Actual output => 
 *    masterQuery: {
 *        postcode: [object Promise]
 *    }
 */

console.log(masterQuery);

到Maven编译器插件。