Provides a singleton over a universally configured FasterXML Jackson JSON
ObjectMapper
instance API.
This is intended to unify the access of Jackson object mappers to avoid multiple separately configured instances floating about in a single project.
Additionally, provides a set of helper/utility methods for working with Jackson APIs in Kotlin.
build.gradle.kts
dependencies {
implementation("org.veupathdb.lib:jackson-singleton:3.2.0")
}
import org.veupathdb.lib.jackson.Json
// Creates a new ObjectNode representing the JSON:
// {
// "key": "value"
// }
fun createObject(): ObjectNode = Json.new {
put("key", "value")
}
// Parses a `Person` instance.
//
// This method uses the return type Person to shortcut
// to Mapper.readValue(inputStream, Person::class.java)
fun parseJson(): Person =
Json.parse(File("foo.json").inputStream())