Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@
<artifactId>jackson-dataformat-xml</artifactId>
<scope>test</scope>
</dependency>
<!-- 06-Apr-2025, tatu: JSR-310 module merged in jackson-databind
for 3.0.0-rc3
-->
<!--
<dependency>
<!-- needed for kotlin.time.Duration converter test -->
<groupId>tools.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<scope>test</scope>
</dependency>
-->
</dependencies>

<build>
Expand Down
25 changes: 12 additions & 13 deletions src/test/kotlin/tools/jackson/module/kotlin/test/DurationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING
import tools.jackson.databind.SerializationFeature
import tools.jackson.databind.json.JsonMapper
import tools.jackson.datatype.jsr310.JavaTimeModule
import tools.jackson.module.kotlin.KotlinFeature
import tools.jackson.module.kotlin.kotlinModule
import tools.jackson.module.kotlin.readValue
Expand All @@ -24,7 +23,7 @@ class DurationTests {

@Test
fun `should serialize Kotlin duration using Java time module`() {
val mapper = mapperBuilder.addModule(JavaTimeModule())
val mapper = mapperBuilder
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.build()

Expand All @@ -35,7 +34,7 @@ class DurationTests {

@Test
fun `should deserialize Kotlin duration`() {
val mapper = mapperBuilder.addModule(JavaTimeModule()).build()
val mapper = mapperBuilder.build()

val result = mapper.readValue<KotlinDuration>("\"PT1H\"")

Expand All @@ -44,7 +43,7 @@ class DurationTests {

@Test
fun `should serialize Kotlin duration inside list using Java time module`() {
val mapper = mapperBuilder.addModule(JavaTimeModule())
val mapper = mapperBuilder
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.build()

Expand All @@ -55,7 +54,7 @@ class DurationTests {

@Test
fun `should deserialize Kotlin duration inside list`() {
val mapper = mapperBuilder.addModule(JavaTimeModule()).build()
val mapper = mapperBuilder.build()

val result = mapper.readValue<List<KotlinDuration>>("""["PT1H","PT2H","PT3H"]""")

Expand All @@ -64,7 +63,7 @@ class DurationTests {

@Test
fun `should serialize Kotlin duration inside map using Java time module`() {
val mapper = mapperBuilder.addModule(JavaTimeModule())
val mapper = mapperBuilder
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.build()

Expand All @@ -81,7 +80,7 @@ class DurationTests {

@Test
fun `should deserialize Kotlin duration inside map`() {
val mapper = mapperBuilder.addModule(JavaTimeModule()).build()
val mapper = mapperBuilder.build()

val result = mapper.readValue<Map<String, KotlinDuration>>("""{"a":"PT1H","b":"PT2H","c":"PT3H"}""")

Expand Down Expand Up @@ -109,7 +108,7 @@ class DurationTests {

@Test
fun `should serialize Kotlin duration inside data class using Java time module`() {
val mapper = mapperBuilder.addModule(JavaTimeModule())
val mapper = mapperBuilder
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.disable(SerializationFeature.WRITE_DURATIONS_AS_TIMESTAMPS)
.build()
Expand All @@ -121,7 +120,7 @@ class DurationTests {

@Test
fun `should deserialize Kotlin duration inside data class`() {
val mapper = mapperBuilder.addModule(JavaTimeModule()).build()
val mapper = mapperBuilder.build()

val result = mapper.readValue<Meeting>("""{"start":"2023-06-20T14:00:00Z","duration":"PT1H30M"}""")

Expand All @@ -131,7 +130,7 @@ class DurationTests {

@Test
fun `should deserialize Kotlin duration inside data class using mixin`() {
val mapper = mapperBuilder.addModule(JavaTimeModule())
val mapper = mapperBuilder
.addMixIn(Meeting::class.java, MeetingMixin::class.java)
.build()

Expand All @@ -143,7 +142,7 @@ class DurationTests {

@Test
fun `should serialize Kotlin duration inside data class using Java time module and mixin`() {
val mapper = mapperBuilder.addModule(JavaTimeModule())
val mapper = mapperBuilder
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
.addMixIn(Meeting::class.java, MeetingMixin::class.java)
.build()
Expand Down Expand Up @@ -173,7 +172,7 @@ class DurationTests {

@Test
fun `should serialize Kotlin duration exactly as Java duration`() {
val mapper = mapperBuilder.addModule(JavaTimeModule()).build()
val mapper = mapperBuilder.build()

val jdto = JDTO()
val kdto = KDTO()
Expand All @@ -198,7 +197,7 @@ class DurationTests {

@Test
fun `should deserialize using custom units specified by format annotation`() {
val mapper = mapperBuilder.addModule(JavaTimeModule()).build()
val mapper = mapperBuilder.build()

val actual = mapper.readValue<DurationWithFormattedUnits>("""{"formatted":1,"default":1}""")

Expand Down