Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use custom object mapper to serialize json in order to avoid null values #2106

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.jaxrs.listing;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.ApiOperation;

import javax.servlet.ServletConfig;
Expand All @@ -25,7 +26,7 @@ public Response getListingJson(
@Context Application app,
@Context ServletConfig sc,
@Context HttpHeaders headers,
@Context UriInfo uriInfo) {
@Context UriInfo uriInfo) throws JsonProcessingException {
return getListingJsonResponse(app, context, sc, headers, uriInfo);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.jaxrs.listing;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -25,7 +26,7 @@ public Response getListing(
@Context ServletConfig sc,
@Context HttpHeaders headers,
@Context UriInfo uriInfo,
@PathParam("type") String type) {
@PathParam("type") String type) throws JsonProcessingException {
if (StringUtils.isNotBlank(type) && type.trim().equalsIgnoreCase("yaml")) {
return getListingYamlResponse(app, context, sc, headers, uriInfo);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;
Expand All @@ -10,6 +11,7 @@
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;
Expand Down Expand Up @@ -161,11 +163,11 @@ protected Response getListingJsonResponse(
ServletContext servletContext,
ServletConfig servletConfig,
HttpHeaders headers,
UriInfo uriInfo) {
UriInfo uriInfo) throws JsonProcessingException {
Swagger swagger = process(app, servletContext, servletConfig, headers, uriInfo);

if (swagger != null) {
return Response.ok().entity(swagger).build();
return Response.ok().entity(Json.mapper().writeValueAsString(swagger)).type(MediaType.APPLICATION_JSON_TYPE).build();
} else {
return Response.status(404).build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;
Expand All @@ -24,7 +25,7 @@ public void shouldCheckModelsSet() {
}

@Test
public void shouldHandleNullServletConfig_issue1689() {
public void shouldHandleNullServletConfig_issue1689() throws JsonProcessingException {
ApiListingResource a = new ApiListingResource();
try {
a.getListing(null, null, null, null, "json");
Expand All @@ -38,7 +39,7 @@ public void shouldHandleNullServletConfig_issue1689() {

}
@Test
public void shouldHandleErrorServletConfig_issue1691() {
public void shouldHandleErrorServletConfig_issue1691() throws JsonProcessingException {

ServletConfig sc = new ServletConfig() {
@Override
Expand Down