All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lenses.jdbc4.JacksonSupport.kt Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package io.lenses.jdbc4

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import java.io.InputStream

object JacksonSupport {

  val mapper: ObjectMapper = ObjectMapper().apply {
    this.registerModule(KotlinModule())
    this.setSerializationInclusion(JsonInclude.Include.NON_NULL)
    this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
    this.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false)
    this.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
    this.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)
    this.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
  }

  fun  toJson(t: T): String = io.lenses.jdbc4.JacksonSupport.mapper.writeValueAsString(t)

  inline fun  fromJson(json: String): T {
    return io.lenses.jdbc4.JacksonSupport.mapper.readValue(json, T::class.java)
  }

  inline fun  fromJson(stream: InputStream): T {
    return io.lenses.jdbc4.JacksonSupport.mapper.readValue(stream, T::class.java)
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy