Spingfox not recognizing custom serializer when generating JSON model for swagger Spingfox not recognizing custom serializer when generating JSON model for swagger json json

Spingfox not recognizing custom serializer when generating JSON model for swagger


Hey I know this is an old question but i stumbled uppon the same problem and done a little research.

The solution is quite simple. Write a class wich represents your custom serialized object. Then just use the directModelSubstitute method in your Docket method to substitute your original model class with the serialized model.

If your serializer does something like this to serialise the DateTime into UNIX Time (Long)

public void serialize(final DateTime value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException, JsonProcessingException {        long millis = value.getMillis();        gen.writeNumber(millis);}

Just add .directModelSubstitute(DateTime.class, Long.class) this line to your Docket definition.