|
| 1 | +package com.fasterxml.jackson.module.kotlin.test.github |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonIdentityInfo |
| 4 | +import com.fasterxml.jackson.annotation.ObjectIdGenerators |
| 5 | +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper |
| 6 | +import org.junit.Test |
| 7 | +import java.util.UUID |
| 8 | +import kotlin.test.assertEquals |
| 9 | + |
| 10 | +class TestGithub194 { |
| 11 | + val id: UUID = UUID.fromString("149800a6-7855-4e09-9185-02e442da8013") |
| 12 | + val json = """{"id": "$id", "name": "Foo"}""" |
| 13 | + |
| 14 | + @Test |
| 15 | + fun testIdentityInfo() { |
| 16 | + val mapper = jacksonObjectMapper() |
| 17 | + val value = mapper.readValue(json, WithIdentity::class.java) |
| 18 | + assertEquals(id, value.id) |
| 19 | + assertEquals(id.toString(), value.idString) |
| 20 | + assertEquals("Foo", value.name) |
| 21 | + } |
| 22 | + |
| 23 | + @JsonIdentityInfo( |
| 24 | + property = "id", |
| 25 | + scope = WithIdentity::class, |
| 26 | + generator = ObjectIdGenerators.PropertyGenerator::class |
| 27 | + ) |
| 28 | + class WithIdentity(val id: UUID, |
| 29 | + val idString: String = id.toString(), |
| 30 | + val name: String) |
| 31 | + |
| 32 | + @Test |
| 33 | + fun testIdentityInfo_WithDefaultId() { |
| 34 | + val mapper = jacksonObjectMapper() |
| 35 | + val value = mapper.readValue(json, WithIdentityAndDefaultId::class.java) |
| 36 | + assertEquals(id, value.id) |
| 37 | + assertEquals(id.toString(), value.idString) |
| 38 | + assertEquals("Foo", value.name) |
| 39 | + } |
| 40 | + |
| 41 | + @JsonIdentityInfo( |
| 42 | + property = "id", |
| 43 | + scope = WithIdentityAndDefaultId::class, |
| 44 | + generator = ObjectIdGenerators.PropertyGenerator::class |
| 45 | + ) |
| 46 | + class WithIdentityAndDefaultId(val id: UUID, |
| 47 | + val idString: String = id.toString(), |
| 48 | + val name: String) |
| 49 | +} |
0 commit comments