Created
November 28, 2018 17:59
-
-
Save WaffleLapkin/865abc51e304b8132b8930dee6cfb4bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test | |
import com.fasterxml.jackson.databind.ObjectMapper | |
import com.fasterxml.jackson.module.kotlin.readValue | |
data class Data<T>(val data: T, val smt: String) | |
fun main(args: Array<String>) { | |
val str = "{\"data\":\"some string\", \"smt\":\"some name\"}" | |
val r = readSmth<String>() | |
println(r) | |
} | |
fun <T : Any>readSmth(): Data<T> { | |
val str = "{\"data\":\"some string\", \"smt\":\"some name\"}" | |
val objectMapper = ObjectMapper() | |
return objectMapper.readValue<Data<T>>(str) | |
} | |
inline fun <reified T: Any> parseJson(json: String): T { | |
val objectMapper = ObjectMapper() | |
return objectMapper.readValue<Data<T>>(json).data | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment