Commit 8cfcd932 authored by Christophe Henry's avatar Christophe Henry

Fix handle absent newestItemTimestampUsec when unread counts are returned

parent 0c1b5e76
......@@ -13,7 +13,7 @@ data class UnreadCount(
val id: String,
val count: Int,
@JsonDeserialize(using = MicroSecTimestampDeserializer::class)
val newestItemTimestampUsec: LocalDateTime
val newestItemTimestampUsec: LocalDateTime = LocalDateTime.now()
)
class MicroSecTimestampDeserializer: LocalDateTimeDeserializer() {
......
......@@ -20,6 +20,10 @@ import org.apache.commons.text.StringEscapeUtils
import org.apache.commons.text.WordUtils
import kotlin.reflect.full.companionObjectInstance
val JACKSON_OBJECT_MAPPER = ObjectMapper().registerKotlinModule()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(JodaModule())
inline fun <reified T: Any> Request.promiseWithSerializer(
loader: ResponseDeserializable<T>? = null
): Promise<T, Exception> {
......@@ -37,13 +41,7 @@ inline fun <reified T: Any> Request.promiseWithSerializer(
return asyncRequest {responseObject(finalLoader)}
}
inline fun <reified T: Any> Request.promise() = asyncRequest {
responseObject<T>(
ObjectMapper().registerKotlinModule()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(JodaModule())
)
}
inline fun <reified T: Any> Request.promise() = asyncRequest {responseObject<T>(JACKSON_OBJECT_MAPPER)}
fun Request.promiseString() = asyncRequest {responseString()}
......
package fr.chenry.android.freshrss.store.api.models
import fr.chenry.android.freshrss.utils.JACKSON_OBJECT_MAPPER
import org.joda.time.*
import org.junit.*
import org.junit.Assert.assertEquals
class UnreadCountTest {
@Before
fun setUp() {
DateTimeUtils.setCurrentMillisFixed(System.currentTimeMillis())
}
@After
fun tearDown() {
DateTimeUtils.setCurrentMillisSystem()
}
@Test
fun testDeserialize() {
val value = JACKSON_OBJECT_MAPPER.readValue(
"""
{
"id": "feed/3",
"count": 0,
"newestItemTimestampUsec": "1552432206000000"
}
""".trimIndent(), UnreadCount::class.java
)
assertEquals(
UnreadCount("feed/3", 0, LocalDateTime("1552432206000000".toLong().div(1000), DateTimeZone.UTC)),
value
)
}
@Test
fun testDeserializeWithNullTimestamp() {
val value = JACKSON_OBJECT_MAPPER.readValue(
"""
{
"id": "feed/3",
"count": 0
}
""".trimIndent(), UnreadCount::class.java
)
assertEquals(UnreadCount("feed/3", 0, LocalDateTime.now()), value)
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment