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

io.datalbry.precise.serialization.jackson.deserializer.GenericDocumentDeserializer.kt Maven / Gradle / Ivy

There is a newer version: 0.0.11
Show newest version
package io.datalbry.precise.serialization.jackson.deserializer

import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.deser.std.StdDeserializer
import com.fasterxml.jackson.databind.deser.std.StdNodeBasedDeserializer
import io.datalbry.precise.api.schema.Schema
import io.datalbry.precise.api.schema.document.Document
import io.datalbry.precise.api.schema.document.generic.GenericDocument

/**
 * [StdDeserializer] implementation to deserialize JSON to [Document]
 *
 * @author timo gruen - 2021-03-16
 */
class GenericDocumentDeserializer(schema: Schema) : StdNodeBasedDeserializer(Document::class.java) {

    private val recordDeserializer = GenericRecordDeserializer(schema)

    override fun convert(node: JsonNode, ctxt: DeserializationContext): Document {
        val id = node.get("id").asText()
        val record = recordDeserializer.convert(node, ctxt)
        return GenericDocument(record.type, id, record.fields)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy