You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@sitole I think for that you will need something like:
import com.fasterxml.jackson.core.type.TypeReference
import com.fasterxml.jackson.databind.ObjectMapper
class Company<P>(
val id: Int,
val props: P
) {
companion object {
inline fun <reified P> fromJson(json: String, mapper: ObjectMapper): Company<P> {
// This creates a type reference based on the provided type P.
val typeRef: TypeReference<Company<P>> = object : TypeReference<Company<P>>() {}
// Use the mapper to read the value with the type information.
return mapper.readValue(json, typeRef)
}
}
}
and then use it like: val company: Company<CustomCompanyProperties> = Company.fromJson(json, objectMapper)
if you want, you can include the mapper inside the Company, like that will be only necessary the json as parameter.
Introduction
Right now API
properties
attribute in company response (https://github.com/goforboom/hubspot/blob/main/hubspot/src/main/kotlin/com/goforboom/hubspot/domain/company/Company.kt) is mapped just to dummyMap<String, Any>
object but would be great to map it to custom value object (same in requests).Issue description
There is some trouble with Generic and Jackson mapping because FasterXML/jackson-databind#921 and
LinkedHashMap
because Java lost Generic information in runtime and Jackson is no able to map incoming request property to right type. I partially fix this issue in our Fakturoid implementation (https://github.com/goforboom/fakturoid/blob/1dd7dfbcbd9e4b6166c1965ce38aed58435b33c3/fakturoid/src/main/kotlin/com/goforboom/fakturoid/model/mapper/Mapper.kt#L20) withTypeReference<R>
but in current implementation problem is deeper, we want to transfer type with generic in generic:Any help is welcome! 🙌🏼
The text was updated successfully, but these errors were encountered: