TofuBeer
TofuBeer

Reputation: 61526

Swagger lists of generics have type "any" instead of appropriate type

I am using swagger-jaxrs_2.10.0 version 1.2.3 (just upgraded from 1.2.2 which had the same result)

If I have a class like this:

public class XXXResponse
{
    private List<Boolean> booleans;
    private List<Byte> bytes;
    private List<Short> shorts;
    private List<Integer> integers;
    private List<Long> longs;
    private List<Float> floats;
    private List<Double> doubles;
    private List<String> strings;
    private List<Date> dates;

    // set/get methods
}

Swagger reports it as:

{
  "integers": [
    "int"
  ],
  "bytes": [
    "any"
  ],
  "longs": [
    "any"
  ],
  "dates": [
    "any"
  ],
  "shorts": [
    "any"
  ],
  "strings": [
    "string"
  ],
  "doubles": [
    "any"
  ],
  "floats": [
    "any"
  ],
  "booleans": [
    "boolean"
  ]
}

What specific magic do I need to incant to make the "any" turn into the appropriate types?

Upvotes: 1

Views: 1100

Answers (1)

TofuBeer
TofuBeer

Reputation: 61526

Turns out that that configuring Jackson did the trick:

JacksonJsonProvider.java

@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonJsonProvider extends JacksonJaxbJsonProvider 
{
    private static ObjectMapper commonMapper = null;

    public JacksonJsonProvider() 
    {
        if(commonMapper == null)
        {
            ObjectMapper mapper = new ObjectMapper();

            mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
            mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
            mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);    
            commonMapper = mapper;
        }

        super.setMapper(commonMapper);
    }
}

Upvotes: 1

Related Questions