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

no.nav.helse.streams.JsonDeserializer.kt Maven / Gradle / Ivy

There is a newer version: 608122d
Show newest version
package no.nav.helse.streams

import org.apache.kafka.common.serialization.*
import org.json.*
import org.slf4j.*

class JsonDeserializer: Deserializer {
   private val log = LoggerFactory.getLogger("JsonDeserializer")

   override fun configure(configs: MutableMap?, isKey: Boolean) { }

   override fun deserialize(topic: String?, data: ByteArray?): JSONObject? {
      return data?.let {
         val json = String(it)
         try {
             JSONObject(json)
         } catch (ex: Exception) {
            log.warn("'$json' is not valid json")
            null
         }
      }
   }

   override fun close() { }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy