title: Null values on swagger JSON file
body: <p>I'm having some trouble with the JSON swagger document generated through Java annotation (REST are exposed using Jersey, serialization is handled by Jackson). Looking at the generated Swagger, it includes <code>null</code> values, which cause the swagger UI to crash (the generated YAML doesn't have this issue).</p>
  
  <p>Here an extract of the JSON:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "swagger": "2.0",
    "info": { "description": null, "version": "1.0.0", "title": "", "termsOfService": null, "contact": null, "license": null },
    "host": "localhost:8080",
    "basePath": "/api",
    "tags": [ { "name": "dataset", "description": null, "externalDocs": null } ],
    "schemes": [ "http" ],
    "consumes": null,
    "produces": null,
    "paths": {
      "/dataset": {
        "get": {
          "tags": ["dataset"],
          "summary": "A dataset",
          "description": "All the available datasets",
          "operationId": "datasetGet",
          "schemes": null,
          "consumes": null,
          "produces": ["application/json"],
          "parameters": [],
          "responses": {
            "200": {
              "description": "Available datasets",
              "schema": {
                "type": "object",
                "format": null,
                "example": null,
                "xml": null,
                "position": null,
                "description": null,
                "title": null,
                "readOnly": null,
                "additionalProperties": {
                  "type": "object",
                  "format": null,
                  "example": null,
                  "xml": null,
                  "position": null,
                  "description": null,
                  "title": null,
                  "readOnly": null,
                  "additionalProperties": {
                    "type": "object",
                    "format": null,
                    "example": null,
                    "xml": null,
                    "position": null,
                    "description": null,
                    "title": null,
                    "readOnly": null,
                    "properties": null
                  }
                }
              },
              "examples": null,
              "headers": null
            }
          },
          "security": null,
          "externalDocs": null,
          "deprecated": null
        },
        "head": null,
        "post": null,
        "put": null,
        "delete": null,
        "options": null,
        "patch": null,
        "parameters": null
      }
    },
    "parameters": null,
    "responses": null,
    "externalDocs": null,
    "securityRequirement": null
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/11757487/how-to-tell-jackson-to-ignore-a-field-during-serialization-if-its-value-is-null">This solution</a> suggest to set the object mapper to omit the <code>null</code> value to solve the issue, but the reality is that I don't know where or how to easily access the mapper, and using <code>NON_NULL</code> annotations on the REST service class is pointless. A similar question <a href="https://stackoverflow.com/questions/33227114/swagger-json-produces-null-value-it-stops-ui">has been asked</a> as well, but I don't use Spring (so I don't have a place to set a custom mapper or setting for it).</p>
  
  <p>I used Swagger in the past, but with different configuration settings (combined with wink, now I'm using Jersey) and didn't have this issue.</p>
  
  <p>In case there is some obvious misconfiguration, this is my <code>web.xml</code>:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"&gt;
  
      &lt;display-name&gt;MyProject&lt;/display-name&gt;
  
      &lt;!-- Rest services mapping --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;jersey&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;init-param&gt;
          &lt;param-name&gt;jersey.config.server.provider.classnames&lt;/param-name&gt;
          &lt;param-value&gt;
              io.swagger.jersey.listing.ApiListingResourceJSON,
              org.something.DatasetApi
          &lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;jersey&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/service/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;!-- Swagger config class --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;DefaultJaxrsConfig&lt;/servlet-name&gt;
          &lt;servlet-class&gt;io.swagger.jaxrs.config.DefaultJaxrsConfig&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;api.version&lt;/param-name&gt;
              &lt;param-value&gt;1.0.0&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;swagger.api.basepath&lt;/param-name&gt;
              &lt;param-value&gt;http://localhost:8080/api&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;!-- Just the CORS filter --&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;ApiOriginFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;org.something.ApiOriginFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;ApiOriginFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>And this is my pom.xml (I'm always confused with swagger dependencies):</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;groupId&gt;org.something&lt;/groupId&gt;
      &lt;artifactId&gt;my_project&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;name&gt;My Project&lt;/name&gt;
      &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
      &lt;build&gt;&lt;finalName&gt;MyProject&lt;/finalName&gt;&lt;/build&gt;
  
      &lt;properties&gt;
          &lt;maven.compiler.source&gt;1.6&lt;/maven.compiler.source&gt;
          &lt;maven.compiler.target&gt;1.6&lt;/maven.compiler.target&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;ch.qos.logback&lt;/groupId&gt;
              &lt;artifactId&gt;logback-classic&lt;/artifactId&gt;
              &lt;version&gt;1.0.13&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.8.1&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" --&gt;
              &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
              &lt;version&gt;2.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- Required only when you are using JAX-RS Client --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.core&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-client&lt;/artifactId&gt;
              &lt;version&gt;2.6&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
              &lt;!-- scope&gt;provided&lt;/scope --&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.jaxrs&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-jaxrs-json-provider&lt;/artifactId&gt;
              &lt;version&gt;2.4.2&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;io.swagger&lt;/groupId&gt;
              &lt;artifactId&gt;swagger-jersey2-jaxrs&lt;/artifactId&gt;
              &lt;version&gt;1.5.4&lt;/version&gt;
          &lt;/dependency&gt;
  
      &lt;/dependencies&gt;
  
  
  &lt;/project&gt;
  </code></pre>
  
  <p>Finally, for completeness, this is an extract of my Java class:</p>
  
  <pre class="lang-java prettyprint-override"><code>package org.something;
  
  import io.swagger.annotations.Api;
  import io.swagger.annotations.ApiOperation;
  import io.swagger.annotations.ApiResponse;
  import io.swagger.annotations.ApiResponses;
  
  import java.util.Map;
  
  import javax.ws.rs.GET;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.Response;
  
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  @Path("/dataset")
  @Produces({ "application/json" })
  @Api(value = "/dataset", description = "the dataset API")
  public class DatasetApi  {
  
      private static final Logger log = LoggerFactory.getLogger(DatasetApi.class);
  
      @GET
      @ApiOperation(value = "All the available datasets.", notes = "Available datasets", response = Map.class, responseContainer = "Map")
      @ApiResponses(value = { @ApiResponse(code = 200, message = "Map of the available datasets", response = Map.class, responseContainer = "Map") })
      public Map&lt;String, String&gt; datasetGet() {
          try {
              log.info("Returning list of dataset");
              return Storage.datasets().getDatasets();
          } catch(Exception e) {
              log.info("Exception!", e);
              throw new WebJsonException(e, Response.Status.INTERNAL_SERVER_ERROR);
          }
      }
  
  }
  </code></pre>
  
  <p>Ideally I'd like to have a class which either is called before or wrap the swagger logic (by declaring it in the <code>web.xml</code>) and does a simple <code>mapper.setSerializationInclusion(Include.NON_NULL);</code> which solves all the troubles, but I don't know if and how this is possible.</p>