1

I am building RESTful Web services using Apache Camel (version 2.15.3), producing JSON output. Camel-swagger is used for API documentation.

There is a DTO which has a java.time.ZonedDateTime field. Since that object can be very ugly in JSON, I applied a custom Serializer for that field. It looks like this in the DTO:

@JsonSerialize(using = ZonedDateTimeSerializer.class)
private ZonedDateTime created;

The ZonedDateTimeSerializer class is just creating a ZonedDateTimeVO class, which is my custom form of ZonedDateTime.

With this setup, swagger creates a model for my DTO with the ZonedDateTime property (type: $ref ZonedDateTime). It also creates the models for ZonedDateTime and its field objects. This is not valid, since the endpoints are not returning a ZonedDateTime (but my custom representation). I'd like to tell swagger to create a model for my custom ZonedDateTimeVO class.

I tried so far: annotating the created field in my DTO with @ApiModelProperty(dataType = "ZonedDateTimeVO") annotation and adding @ApiModel annotation to ZonedDateTimeVO class. This way swagger creates a model for my DTO with property of ZonedDateTimeVO (type: $ref ZonedDateTimeVO), but it does not create a model for ZonedDateTimeVO itself. That is the problem actually, I cannot make swagger "scan" or "find" my custom type.

How should I do it?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
vargen_
  • 2,590
  • 3
  • 24
  • 30
  • Have you checked this thread http://stackoverflow.com/questions/29355872/how-to-set-apimodelproperty-datatype-to-string-for-swagger-documentation? – Sergey Nov 05 '15 at 16:40
  • @Sergey I did not read it yet, thanks for pointing out. I don't think it is relevant for me though. I was able to use dataType="string" in another DTO. – vargen_ Nov 05 '15 at 17:26
  • If you are using jackson I would recommend using [the threeten module](https://github.com/FasterXML/jackson-datatype-jsr310) – assylias Nov 13 '15 at 18:58

0 Answers0