Skip to content

Commit 3bce461

Browse files
author
christianc
committed
Revert "use custom object mapper to serialize json in order to avoid
null values" This reverts commit 3ad7595. This fixes issue swagger-api#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).
1 parent 222ef10 commit 3bce461

File tree

4 files changed

+6
-11
lines changed

4 files changed

+6
-11
lines changed

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/AcceptHeaderApiListingResource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.jaxrs.listing;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.annotations.ApiOperation;
54

65
import javax.servlet.ServletConfig;
@@ -26,7 +25,7 @@ public Response getListingJson(
2625
@Context Application app,
2726
@Context ServletConfig sc,
2827
@Context HttpHeaders headers,
29-
@Context UriInfo uriInfo) throws JsonProcessingException {
28+
@Context UriInfo uriInfo) {
3029
return getListingJsonResponse(app, context, sc, headers, uriInfo);
3130
}
3231

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/ApiListingResource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.jaxrs.listing;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.annotations.ApiOperation;
54
import org.apache.commons.lang3.StringUtils;
65

@@ -26,7 +25,7 @@ public Response getListing(
2625
@Context ServletConfig sc,
2726
@Context HttpHeaders headers,
2827
@Context UriInfo uriInfo,
29-
@PathParam("type") String type) throws JsonProcessingException {
28+
@PathParam("type") String type) {
3029
if (StringUtils.isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) {
3130
return getListingYamlResponse(app, context, sc, headers, uriInfo);
3231
} else {

modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/listing/BaseApiListingResource.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger.jaxrs.listing;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.config.FilterFactory;
54
import io.swagger.config.Scanner;
65
import io.swagger.config.SwaggerConfig;
@@ -11,7 +10,6 @@
1110
import io.swagger.jaxrs.config.ReaderConfigUtils;
1211
import io.swagger.jaxrs.config.SwaggerContextService;
1312
import io.swagger.models.Swagger;
14-
import io.swagger.util.Json;
1513
import io.swagger.util.Yaml;
1614
import org.slf4j.Logger;
1715
import org.slf4j.LoggerFactory;
@@ -163,11 +161,11 @@ protected Response getListingJsonResponse(
163161
ServletContext servletContext,
164162
ServletConfig servletConfig,
165163
HttpHeaders headers,
166-
UriInfo uriInfo) throws JsonProcessingException {
164+
UriInfo uriInfo) {
167165
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);
168166

169167
if (swagger != null) {
170-
return Response.ok().entity(Json.mapper().writeValueAsString(swagger)).type(MediaType.APPLICATION_JSON_TYPE).build();
168+
return Response.ok().entity(swagger).build();
171169
} else {
172170
return Response.status(404).build();
173171
}

modules/swagger-jaxrs/src/test/java/io/swagger/ApiListingResourceTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swagger;
22

3-
import com.fasterxml.jackson.core.JsonProcessingException;
43
import io.swagger.jaxrs.Reader;
54
import io.swagger.jaxrs.listing.ApiListingResource;
65
import io.swagger.models.Swagger;
@@ -25,7 +24,7 @@ public void shouldCheckModelsSet() {
2524
}
2625

2726
@Test
28-
public void shouldHandleNullServletConfig_issue1689() throws JsonProcessingException {
27+
public void shouldHandleNullServletConfig_issue1689() {
2928
ApiListingResource a = new ApiListingResource();
3029
try {
3130
a.getListing(null, null, null, null, "json");
@@ -39,7 +38,7 @@ public void shouldHandleNullServletConfig_issue1689() throws JsonProcessingExcep
3938

4039
}
4140
@Test
42-
public void shouldHandleErrorServletConfig_issue1691() throws JsonProcessingException {
41+
public void shouldHandleErrorServletConfig_issue1691() {
4342

4443
ServletConfig sc = new ServletConfig() {
4544
@Override

0 commit comments

Comments
 (0)