-
-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Generic mapping of java.util.Optional field does not work
To Reproduce
data class O1(val value: Optional<String>)
data class O2 (val value: String?)
object OMapper: ObjectMappie<O1, O2>() {
// works fine
fun mapOptional(value: Optional<String>) = value.orElse(null)
// Fails with 'cannot assign source type Optional<String> to target type String?'
//fun <T> mapOptional(value: Optional<T>): T? = value.orElse(null)
}
fun main () {
OMapper.map(O1(Optional.empty())).let(::println)
OMapper.map(O1(Optional.of("test"))).let(::println)
}Expected behavior
java.util.Optional can be generically mapped to nullable T and vice-versa, currently it only possible to map by explicitly specifying generic type
Kotlin version
2.3.0
Mappie version
2.3.0-2.3.1
Mappie and Kotlin compatibility
Yes
Invocation method
Gradle
Additional context
Can it be considered to add Optional<-> Nullable as build-in mapper?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working