Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将java.time.Instant与Swagger 2.x一起使用?_Java_Swagger_Swagger 2.0 - Fatal编程技术网

如何将java.time.Instant与Swagger 2.x一起使用?

如何将java.time.Instant与Swagger 2.x一起使用?,java,swagger,swagger-2.0,Java,Swagger,Swagger 2.0,我的JavaWebApp中有一个REST端点,它接受一个瞬间作为查询参数,如下面的代码所示 @GET @Produces(MediaType.APPLICATION_JSON) Response getHistory( @QueryParam("beforeTime") Instant beforeTime, @QueryParam("afterTime") Instant afterTime) { ... }

我的JavaWebApp中有一个REST端点,它接受一个瞬间作为查询参数,如下面的代码所示

@GET
@Produces(MediaType.APPLICATION_JSON)
Response getHistory(
    @QueryParam("beforeTime")
    Instant beforeTime,

    @QueryParam("afterTime")
    Instant afterTime) {
    ...
}

这在swagger 1.x下运行得很好,但是当我们切换到swagger 2.x时,
Instant
的对象显示为
$int64
,而不是日期时间字段。我能用这些招摇过市的注释做些什么才能让它起作用?

我能够使用@ApiParam注释来解决这个问题。将类型设置为
date-time
并将格式设置为
java.time.Instant
修复了该问题

@GET
@Produces(MediaType.APPLICATION_JSON)
Response getHistory(
    @QueryParam("beforeTime")
    @ApiParam(type="date-time", format = "java.time.Instant")
    Instant beforeTime,

    @QueryParam("afterTime")
    @ApiParam(type="date-time", format = "java.time.Instant")
    Instant afterTime) {
    ...
}