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.
Example:
val json = """["John","Jane"]"""
val type = JsonSerializer.typeFactory.constructCollectionType(List::class.java, String::class.java)
val list = json.toObject<List<String>>(type)Parameters
The JavaType representing the target type.
Type Parameters
The type of object to deserialize to.
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.
Example:
data class User(val name: String, val age: Int)
val json = """{"name":"John","age":30}"""
val user = json.toObject<User>(User::class.java)Parameters
The Class representing the target type.
Type Parameters
The type of object to deserialize to.
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.
Example:
val json = """{"name":"John","age":30}"""
val node = json.toJsonNode<ObjectNode>()
val user = node.toObject<User>(User::class.java)Parameters
The Class representing the target type.
Type Parameters
The type of object to convert to.
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.
Example:
data class User(val name: String, val age: Int)
val json = """{"name":"John","age":30}"""
val user = json.toObject<User>()Type Parameters
The type of object to deserialize to, inferred from the call site.
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.
Example:
val json = """{"name":"John","age":30}"""
val node = json.toJsonNode<ObjectNode>()
val user = node.toObject<User>()Type Parameters
The type of object to convert to, inferred from the call site.