question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Springfox swagger not working with with JsonView

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
MaksimOrlovcommented, Oct 17, 2019

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>
0reactions
lukszicommented, Nov 21, 2019

@0lig If you’re still looking and for anyone who might come across this, your pom needs to have these dependencies:

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

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

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

since these versions are not in the central maven repository yet you also need to add this to your pom:

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

Also when coming from SpringFox2, you need to replace @EnableSwagger2 with @EnableSwagger2WebMvc in your SwaggerConfig

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springboot swagger not working with with JsonView
I am on the same board and looking for an answer. I was thinking of creating DTO objects, in case if the JsonView...
Read more >
springfox/springfox - Gitter
Working on getting 2.9 to maven central there is a problem with the artifact. ... use the springfox annotations to hide a field...
Read more >
JsonView class with Swagger @ApiResponse-Springboot
Using @RequestParam annotated method with swagger ui · Suddenly Springfox Swagger 3.0 is not working with spring webflux · Swagger with Spring Boot...
Read more >
Springfox Reference Documentation - GitHub Pages
Downloading the source archive and building will NOT work! ... When we started work on 2.0 swagger specification we realized that we're ...
Read more >
OpenAPI 3 Library for spring-boot
OpenAPI 3 Library for spring boot projects. Is based on swagger-ui, to display the OpenAPI description.Generates automatically the OpenAPI ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found