springfox: Springfox swagger not working with with JsonView

Swagger is supposed to support JsonView but I can’t get it to work.

Here are my versions:

<dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
        <exclusions>
            <exclusion>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-annotations</artifactId>
            </exclusion>
            <exclusion>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-models</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-annotations</artifactId>
        <version>1.5.24</version>
    </dependency>
    <dependency>
        <groupId>io.swagger</groupId>
        <artifactId>swagger-models</artifactId>
        <version>1.5.24</version>
    </dependency>

Here is my model:

@JsonView(View.WriteView.class)
    LocalDateTime serviceTime;
    String location;
    String serviceType;
    String assignee;
    String status;

Here is my controller:

@ApiOperation(value = "Create a new order")
@PostMapping("/orders")
@ResponseStatus(HttpStatus.CREATED)
@JsonView({View.WriteView.class})
public Order createOrder(@Valid @RequestBody @JsonView(View.WriteView.class) Order order) {
    return orderRepository.save(order);
}

Both input and output is not working. Here is my swagger UI:

8iGfg iMtWo

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 24 (11 by maintainers)

Most upvoted comments

First you should add snapshot repository

<repositories>
    <repository>
      <id>jcenter-snapshots</id>
      <name>jcenter</name>
      <url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
    </repository>
</repositories>

then relevant dependencies

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-webmvc</artifactId>
    <version>3.0.0-SNAPSHOT</version>
</dependency>