Skip to content

Instantly share code, notes, and snippets.

@glockbender
Created February 4, 2020 15:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glockbender/966bc80383e0893b47cc6edab7e4969d to your computer and use it in GitHub Desktop.
Save glockbender/966bc80383e0893b47cc6edab7e4969d to your computer and use it in GitHub Desktop.
inline fun <reified T> ObjectMapper.readAsList(serialized: String): List<T> =
this.typeFactory.constructCollectionType(List::class.java, T::class.java)
.let { collectionType ->
try {
this.readValue(serialized, collectionType)
} catch (e: Exception) {
throw RuntimeException("Cannot deserialize list of ${T::class.simpleName}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment