LeRiton
LeRiton

Reputation: 343

Working with Java 8 Date/Time API in Spring Boot

I'm working with Java 8 Date/Time API (JSR-310) on a brand new Spring Boot (1.5) application. Prior the first public release we can stay on tip of every dependencies and that's why I want to clarify the state of JSR-310 handling on the complete Spring Boot stack.

Boot Starter Web - Jackson serialization

Just add jackson-datatype-jsr310 dependency.

But is this really necessary? If so, why is this not included in the standard bundle?

Boot Starter Data - Hibernate persistence

This is where it gets tricky. I have struggling a bit with that, maybe because I'm using PostgreSQL.

Seems like Java 8 compatibility was added to JDBC for version 4.2, which means:

Related : PSQLException - spring boot 1.4.1 - spring data jpa - offsetdatetime/localdatetime identified as Bytestream

Everything works as expected, but as of current (Spring Boot 1.5.2) development status, am I doing OK, is there any preferred way?

Thanks in advance

Upvotes: 1

Views: 1810

Answers (1)

Marc Tarin
Marc Tarin

Reputation: 3169

Regarding you first question: the jsr310 dependency is declared as optional in spring-boot-autoconfigure/pom.xml, meaning it's excluded by default unless you declare the dependency in your projet pom.xml.

I can give you a practical example that justifies its being optional. A few weeks ago, I migrated a Spring Boot project from Java 7 to Java 8. This project used the Joda-Time, with a dependency on jackson-datatype-joda API to manage temporal data. My project worked out of the box, without needing to migrate to the new java.time (jsr310) API beforehand. Afterwards I switched to the java.time API and replaced jackson-datatype-joda dependency with the jackson-datatype-jsr310 one. But in the mean time, I was able to work on some urgent issues than a non-required - though recommended - change of API.

Upvotes: 0

Related Questions