FasterXML / FasterXML/jackson-module-kotlin
Exception when using @JsonIdentityInfo
- Dominant language
- Kotlin
- Stars
- 1.2k
- Forks
- 187
- Avg merge
- 9h 48m
- Merged PRs (30d)
- 16
Description
**Describe the bug**
The issue that I am facing similar to [Issue 194](https://github.com/FasterXML/jackson-module-kotlin/issues/194) but extended.
When I try to use the similar setup but json value would not have id property ("{"name": "Foo"}") because that would be automatically created in constructor using `UUID.randomUUID()`.
**To Reproduce**
```
class TestGithub571 {
private val id: UUID = UUID.fromString("149800a6-7855-4e09-9185-02e442da8013")
private val json = """{"name": "Foo"}"""
@Test
fun testIdentityInfo() {
val mapper = jacksonObjectMapper()
val value = mapper.readValue(json, WithIdentity::class.java)
assertEquals(id, value.id)
assertEquals("Foo", value.name)
}
@JsonIdentityInfo(
property = "id",
scope = WithIdentity::class,
generator = ObjectIdGenerators.PropertyGenerator::class
)
class WithIdentity(val id: UUID = UUID.randomUUID(),
val name: String)
@Test
fun testIdentityInfo_WithDefaultId() {
val mapper = jacksonObjectMapper()
val value = mapper.readValue(json, WithIdentityAndDefaultId::class.java)
assertEquals(id, value.id)
assertEquals("Foo", value.name)
}
@JsonIdentityInfo(
property = "id",
scope = WithIdentityAndDefaultId::class,
generator = ObjectIdGenerators.PropertyGenerator::class
)
class WithIdentityAndDefaultId(val id: UUID = UUID.fromString("149800a6-7855-4e09-9185-02e442da8013"),
val name: String)
}
```
**Expected behavior**
I expected the above test cases to get passed because the value for `name` is deserialized from json string and `UUID` is constructed from class constructor.
**Versions**
Kotlin: 1.6.21
Jackson-module-kotlin: 2.13.2
Jackson-databind: 2.13.2.1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.