4

Swagger is suppose 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:

enter image description here enter image description here

Also I have verified that the code does work, calling the REST API only returns one field.

erotsppa
  • 14,248
  • 33
  • 123
  • 181

2 Answers2

0

I am on the same board and looking for an answer. I was thinking of creating DTO objects, in case if the JsonView doesn't work.

spatel
  • 11
  • 2
0

version 3.0.0 supports JsonView, please add the following dependency:

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
            <version>3.0.0</version>
        </dependency>
lamplet
  • 103
  • 1
  • 1
  • 8