I've had a search through the history of this chan...
# arrow
k
I've had a search through the history of this channel but couldn't find anything. I have the following map
mapOf("foo" to "2")
. I want to convert it into the following data class
data class Sample(val foo: Option<Number>)
. I know I can use jacksonObjectMapper to do this if I wasn't using
Option
using
fun fromMap(m: Map<String, String>) = jacksonObjectMapper().convertValue<Sample>(m)
. How can I get jacksonObjectMapper to convert any values I have into
Option
? Providing a
None
value for nulls.
b
I thought maybe this was present in Arrow, but I think the best option you have currently is to pull something like this in scope:
fun <T> T?.asOption(): Option<T> = Option.fromNullable(this)
r
I guess for that case you would have to write a custom marshaller for jackson for Option but I wouldn’t recommend it since nullable types should already be supported and they are isomorphic to option and faster, as Bob said you can always go toOption when you need to.
👍 1
Looks like we already have that thanks to @Alpha Ho
k
Cool. How do I use that module?
Do I need to import something additional when using
arrow-core:0.10.4
?
@raulraja ☝️ ?