Kev
11/17/2024, 4:38 AMString -> Any
and hope the compiler does what it does but I can go from Any -> String
unless there is some unsafe compiler warning I can add to the code (which i want to avoid). What I have is:
enum class Attribute(val label: String, val iso: Iso<String, *>) {
FOO("foo:options", stringToInt),
BAR("bar:values", intToList),
BAZ("baz:id", stringToUuid),
}
typealias NodeAttributes = Map<NodeAttribute, Any>
ColumnAdapter<NodeAttributes, String> =
object : ColumnAdapter<NodeAttributes, String> {
override fun decode(databaseValue: String): NodeAttributes {
val attributes = jacksonObjectMapper().readValue(databaseValue, object : TypeReference<NodeAttributes>() {})
return attributes.mapValues { (key, value) ->
key.iso.get(value.toString()) // type mismatch required any found any?
}
}
override fun encode(value: NodeAttributes): String {
value.mapValues { (key, value) ->
key.iso.reverseGet(value) // Type mismatch required nothing found any
}
return jacksonObjectMapper().writeValueAsString(value)
}
}
Is there a better way to retain type information?Alejandro Serrano.Mena
11/18/2024, 9:52 AMclass Representation<A> private constructor(val representation: String) {
override fun toString() = representation
}
then you can have something going in both directionsAlejandro Serrano.Mena
11/18/2024, 9:53 AMIso<A, String>
, since you do not have a way to move from every string into an A
, just for a subset of those. This is exactly where prisms can help you