From 3bce461292f8dae8a1f97c06fe2add86c9bf30ed Mon Sep 17 00:00:00 2001 From: christianc Date: Thu, 3 Aug 2017 12:59:08 +0200 Subject: [PATCH] Revert "use custom object mapper to serialize json in order to avoid null values" This reverts commit 3ad759596f321ffb195256e045ec5803c00ee53c. This fixes issue #2320. The original commit is pointless and dangerous, as it surprisingly overrides the behavior of SwaggerSerializers.java, but does essentially the same (but without supporting pretty printing). --- .../jaxrs/listing/AcceptHeaderApiListingResource.java | 3 +-- .../java/io/swagger/jaxrs/listing/ApiListingResource.java | 3 +-- .../io/swagger/jaxrs/listing/BaseApiListingResource.java | 6 ++---- .../src/test/java/io/swagger/ApiListingResourceTest.java | 5 ++--- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/AcceptHeaderApiListingResource.java b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/AcceptHeaderApiListingResource.java index 951b49c96e..6a591fb49b 100644 --- a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/AcceptHeaderApiListingResource.java +++ b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/AcceptHeaderApiListingResource.java @@ -1,6 +1,5 @@ package io.swagger.jaxrs.listing; -import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.annotations.ApiOperation; import javax.servlet.ServletConfig; @@ -26,7 +25,7 @@ public Response getListingJson( @Context Application app, @Context ServletConfig sc, @Context HttpHeaders headers, - @Context UriInfo uriInfo) throws JsonProcessingException { + @Context UriInfo uriInfo) { return getListingJsonResponse(app, context, sc, headers, uriInfo); } diff --git a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/ApiListingResource.java b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/ApiListingResource.java index 96d01264a3..93623c10d7 100644 --- a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/ApiListingResource.java +++ b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/ApiListingResource.java @@ -1,6 +1,5 @@ package io.swagger.jaxrs.listing; -import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -26,7 +25,7 @@ public Response getListing( @Context ServletConfig sc, @Context HttpHeaders headers, @Context UriInfo uriInfo, - @PathParam("type") String type) throws JsonProcessingException { + @PathParam("type") String type) { if (StringUtils.isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) { return getListingYamlResponse(app, context, sc, headers, uriInfo); } else { diff --git a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/BaseApiListingResource.java b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/BaseApiListingResource.java index 9b57aae508..d167052ec0 100644 --- a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/BaseApiListingResource.java +++ b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/BaseApiListingResource.java @@ -1,6 +1,5 @@ package io.swagger.jaxrs.listing; -import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.config.FilterFactory; import io.swagger.config.Scanner; import io.swagger.config.SwaggerConfig; @@ -11,7 +10,6 @@ import io.swagger.jaxrs.config.ReaderConfigUtils; import io.swagger.jaxrs.config.SwaggerContextService; import io.swagger.models.Swagger; -import io.swagger.util.Json; import io.swagger.util.Yaml; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -163,11 +161,11 @@ protected Response getListingJsonResponse( ServletContext servletContext, ServletConfig servletConfig, HttpHeaders headers, - UriInfo uriInfo) throws JsonProcessingException { + UriInfo uriInfo) { Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo); if (swagger != null) { - return Response.ok().entity(Json.mapper().writeValueAsString(swagger)).type(MediaType.APPLICATION_JSON_TYPE).build(); + return Response.ok().entity(swagger).build(); } else { return Response.status(404).build(); } diff --git a/modules/swagger-jaxrs/src/test/java/io/swagger/ApiListingResourceTest.java b/modules/swagger-jaxrs/src/test/java/io/swagger/ApiListingResourceTest.java index 9b4f8299df..603d14778f 100644 --- a/modules/swagger-jaxrs/src/test/java/io/swagger/ApiListingResourceTest.java +++ b/modules/swagger-jaxrs/src/test/java/io/swagger/ApiListingResourceTest.java @@ -1,6 +1,5 @@ package io.swagger; -import com.fasterxml.jackson.core.JsonProcessingException; import io.swagger.jaxrs.Reader; import io.swagger.jaxrs.listing.ApiListingResource; import io.swagger.models.Swagger; @@ -25,7 +24,7 @@ public void shouldCheckModelsSet() { } @Test - public void shouldHandleNullServletConfig_issue1689() throws JsonProcessingException { + public void shouldHandleNullServletConfig_issue1689() { ApiListingResource a = new ApiListingResource(); try { a.getListing(null, null, null, null, "json"); @@ -39,7 +38,7 @@ public void shouldHandleNullServletConfig_issue1689() throws JsonProcessingExcep } @Test - public void shouldHandleErrorServletConfig_issue1691() throws JsonProcessingException { + public void shouldHandleErrorServletConfig_issue1691() { ServletConfig sc = new ServletConfig() { @Override