com.tianyisoft.database.jackson.DateDeserializer.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of querybuilder Show documentation
Show all versions of querybuilder Show documentation
A query builder from laravel
The newest version!
package com.tianyisoft.database.jackson
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import java.text.SimpleDateFormat
import java.time.Instant
import java.util.*
class DateDeserializer: JsonDeserializer() {
private val format = "yyyy-MM-dd HH:mm:ss"
override fun deserialize(p0: JsonParser, p1: DeserializationContext?): Date {
return try {
SimpleDateFormat(format).parse(p0.valueAsString)
} catch (e: Exception) {
Date.from(Instant.parse(p0.valueAsString))
}
}
}