https://kotlinlang.org logo
#http4k
Title
m

maybetrinity

06/15/2018, 7:36 AM
Hi! Have some questions about constructing Body Lenses. Appreciate you reading this in advance! Let’s say I have this data class:
Copy code
data class Meeting(
	val date: java.time.LocalDate,
	val time: String
)
Based on the docs I would do
val MeetingBody = Body.auto<Meeting>().toLens()
let’s say I make a request with
{date: "2017-01-22", time: "3:00 PM"}
when I try
MeetingBody.extract(request: Request)
I get
Copy code
Cannot construct instance of `java.time.LocalDate` (no Creators, like default construct, exist): no String-argument constructor/factory method to deserialize from String value ('2017-07-12')
 at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: Meeting["date"])
I would have expected this(^) to work as the following does:
Copy code
val queryResultLens = Query.localDate().required("date")
queryResultLens.extract(Request(Method.GET, "/?date=2017-01-22"))
Similarly, if I wanted to ensure the time matched a given regex, I can do this with a query param:
Copy code
val queryResultLens = Query.regex("v(\\d+)").required("time")
queryResultLens.extract(Request(Method.GET, "/?time=v123"))
but to do it with a body param i'd need to tell Jackson how I want it to be deserialized or?