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.
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)Parameters
The type of object to convert to.
The Class representing the target 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.
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)Parameters
The type of object to convert to.
The JavaType representing the target 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.
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)Parameters
The type of object to convert to.
The TypeReference representing the target type.
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.
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>()Parameters
The type of object to convert to, inferred from the call site.