1

I want to create a model class that contains createdDate feild type as LocalDateTime using swagger contract, when implementing using swagger contract it is generating offsetDateTime as type in dto.

Tried with this approach Details added in swagger:

 createdDate: type: string format: date-time example: 2017-01-13T17:09:42.411 

Please provide correct swagger implementation for this scenario.

1 Answer 1

0

in Java with Spring Boot, you can use the @JsonSerialize and @JsonDeserialize annotations with a custom converter:

import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; public class YourModelClass { @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) @JsonSerialize(using = LocalDateTimeSerializer.class) @JsonDeserialize(using = LocalDateTimeDeserializer.class) private LocalDateTime createdDate; // getters and setters 

}

You would then need to define LocalDateTimeSerializer and LocalDateTimeDeserializer classes that implement the serialization and deserialization logic.

Sign up to request clarification or add additional context in comments.

1 Comment

I cannot create separate model class. I want my model class to be created once building of swagger spec yaml file. In yaml file i defined createdDate: type: string format: date-time example: 2017-01-13T17:09:42.411 , but it was creating type as offsetDatetime but i need LocalDateTime type.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.