convert
Converts this object to the specified target type.
Uses the pre-configured JsonSerializer to convert the object.
Receiver
The object to convert.
Return
The converted object.
Parameters
The type of object to convert to.
The Class representing the target type.
Throws
if conversion fails.
Example:
data class User(val name: String, val age: Int)
data class UserDto(val userName: String, val userAge: Int)
val user = User("John", 30)
val dto = user.convert(UserDto::class.java)Converts this object to the specified target type.
Uses the pre-configured JsonSerializer to convert the object.
Receiver
The object to convert.
Return
The converted object.
Parameters
The type of object to convert to.
The JavaType representing the target type.
Throws
if conversion fails.
Example:
val json = """{"name":"John","age":30}"""
val node = json.toJsonNode<ObjectNode>()
val type = JsonSerializer.typeFactory.constructMapType(HashMap::class.java, String::class.java, Any::class.java)
val map = node.convert<MutableMap<String, Any>>(type)Converts this object to the specified target type.
Uses the pre-configured JsonSerializer to convert the object.
Receiver
The object to convert.
Return
The converted object.
Parameters
The type of object to convert to.
The TypeReference representing the target type.
Throws
if conversion fails.
Example:
data class User(val name: String, val addresses: List<Address>)
val user = User("John", listOf(Address("123 Main St")))
val typeRef = object : TypeReference<User>() {}
val converted = user.convert(typeRef)Converts this object to the specified target type using reified generics.
Convenience method that uses the reified type parameter to avoid specifying the class explicitly.
Receiver
The object to convert.
Return
The converted object.
Parameters
The type of object to convert to, inferred from the call site.
Throws
if conversion fails.
Example:
data class User(val name: String, val age: Int)
data class UserDto(val userName: String, val userAge: Int)
val user = User("John", 30)
val dto = user.convert<UserDto>()