FasterXML / FasterXML/jackson-module-kotlin
Non-deterministic method lookup for Kotlin Data Classes
- Dominant language
- Kotlin
- Stars
- 1.2k
- Forks
- 187
- Avg merge
- 9h 48m
- Merged PRs (30d)
- 16
Description
### Search before asking
- [x] I searched in the [issues](https://github.com/FasterXML/jackson-databind/issues) and found nothing similar.
### Describe the bug
In the case when byte-code has couple of methods with same signature but different return types, the serialization of such object is not deterministic.
I guess this is a problem how Jackson selects the method to execute.
The byte-code with two methods with same signature but different return types can be produced with Kotlin.
For instance:
```kotlin
interface A {
fun getValues(): Collection
}
data class B(val values: List) : A {
override fun getValues(): Collection = values.toSet()
}
```
Will produce such byte-code:
```java
// DECOMPILED
public final class B implements A {
@NotNull
private final List values;
...
@NotNull
public final List getValues() {
return this.values;
}
@NotNull
public Collection getValues() {
return (Collection)CollectionsKt.toSet((Iterable)this.values);
}
...
}
```
### Version Information
2.20.+
3.0.+
### Reproduction
Let's look at this code:
```kotlin
fun main() {
val mapper = jacksonObjectMapper()
val b = B(listOf("a", "a", "a"))
val json = mapper.writeValueAsString(b)
val parsed = mapper.readValue(json, B::class.java)
if (parsed.values != b.values) {
error("Values are different!")
}
}
```
If you run this code couple of times the problem be reproduced.
### Expected behavior
The method lookup should be similar to Java Runtime lookup strategy.
### Additional context
[Discussion](https://youtrack.jetbrains.com/issue/KT-83167) in YouTrack.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.