javajacksonspring-vault

Customise ObjectMapper to serialise LocalDateTime properly


I am using Spring Vault in my project and trying to store a serialised representation of LocalDateTime (ISO date time format) as a secret data in Vault. However, the ObjectMapper used inside Spring Vault doesn't seem to be customisable. So I am unable to register the JavaTimeModule that comes from com.fasterxml.jackson.datatype:jackson-datatype-jsr310.

Is there a way out of this?


Solution

  • As hinted by one of the commentators, I was able to resolve this by using a Jackson annotation. It's not ideal but gets the job done without having to change anything in Spring Vault.

    @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    private OffsetDateTime createdAt