Anorm 2.5 doesn't work with java.time.LocalDate
Asked Answered
R

0

9

I'm using Anorm 2.5 and the following snippet:

import anorm.SqlParser._
import anorm._
// Not really needed, but to be sure
import anorm.JavaTimeToStatement
import anorm.JavaTimeParameterMetaData
import anorm.JavaTimeColumn

val localDate = java.time.LocalDate.of(2015, 9, 25)

val value = SQL"""SELECT id FROM table WHERE date = $localDate;""".as(get[Long]("id").singleOpt)

yields this error:

found   : java.time.LocalDate
[error]  required: anorm.ParameterValue
[error]  date = $localDate

According to the changelog, anorm 2.5 should actually support java.time.LocalDate conversions. Can someone help? In my opinion the java.time.LocalDate support is not working.

Receptor answered 25/9, 2015 at 13:53 Comment(1)
Indeed the doc is wrong. LocalDate is supported as column, but not as parameter for the package java.time. Until this is fix, a workaround is to use .atStartOfDay before passing the LocalDate.Obstetrics

© 2022 - 2024 — McMap. All rights reserved.