Created
March 7, 2021 16:44
-
-
Save njofce/a2bba3bb542f3d8763d82e181c502d70 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Custom datetime serializer | |
private static final LocalDateTimeSerializer CUSTOM_DATE_SERIALIZER = | |
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm")); | |
// Custom datetime deserializer | |
private static final LocalDateTimeDeserializer CUSTOM_DATE_DESERIALIZER = | |
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("dd-MMM-yyyy HH:mm")); | |
// Feign based API | |
public static FileApi getFileAPI() { | |
String URL = "http://localhost:8080"; // This must be passed as an ENV variable | |
return Feign.builder() | |
.encoder(new JacksonEncoder(apiObjectMapper())) | |
.decoder(new JacksonDecoder(apiObjectMapper())) | |
.contract(new SpringMvcContract()) | |
.target(FileApi.class, URL); | |
} | |
// Default object mapper for JacksonEncoder | |
private static ObjectMapper apiObjectMapper() { | |
ObjectMapper mapper = new ObjectMapper(); | |
mapper.registerModule(getTimeModule()); | |
return mapper; | |
} | |
// A custom module that registers datetime serializers/deserializers | |
public static Module getTimeModule() { | |
JavaTimeModule timeModule = new JavaTimeModule(); | |
timeModule.addSerializer(CUSTOM_DATE_SERIALIZER); | |
timeModule.addDeserializer(LocalDateTime.class, CUSTOM_DATE_DESERIALIZER); | |
return timeModule; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment