toObject
Deserializes this JSON string into an object of the specified JavaType.
Uses the pre-configured JsonSerializer to read the value.
Receiver
The JSON string to deserialize.
Return
The deserialized object.
Parameters
The type of object to deserialize to.
The JavaType representing the target type.
Throws
if deserialization fails.
Example:
val json = """["John","Jane"]"""
val type = JsonSerializer.typeFactory.constructCollectionType(List::class.java, String::class.java)
val list = json.toObject<List<String>>(type)Deserializes this JSON string into an object of the specified Class.
Uses the pre-configured JsonSerializer to read the value.
Receiver
The JSON string to deserialize.
Return
The deserialized object.
Parameters
The type of object to deserialize to.
The Class representing the target type.
Throws
if deserialization fails.
Example:
data class User(val name: String, val age: Int)
val json = """{"name":"John","age":30}"""
val user = json.toObject<User>(User::class.java)Converts this JsonNode into an object of the specified Class.
Uses the pre-configured JsonSerializer to convert the tree to value.
Receiver
The JsonNode 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:
val json = """{"name":"John","age":30}"""
val node = json.toJsonNode<ObjectNode>()
val user = node.toObject<User>(User::class.java)Deserializes this JSON string into an object using reified generics.
Convenience method that uses the reified type parameter to avoid specifying the class explicitly.
Receiver
The JSON string to deserialize.
Return
The deserialized object.
Parameters
The type of object to deserialize to, inferred from the call site.
Throws
if deserialization fails.
Example:
data class User(val name: String, val age: Int)
val json = """{"name":"John","age":30}"""
val user = json.toObject<User>()Converts this JsonNode into an object using reified generics.
Convenience method that uses the reified type parameter to avoid specifying the class explicitly.
Receiver
The JsonNode to convert.
Return
The converted object.
Parameters
The type of object to convert to, inferred from the call site.
Throws
if conversion fails.
Example:
val json = """{"name":"John","age":30}"""
val node = json.toJsonNode<ObjectNode>()
val user = node.toObject<User>()