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

ski.gagar.vxutil.vertigram.util.json.AttachmentDeserializer.kt Maven / Gradle / Ivy

The newest version!
package ski.gagar.vxutil.vertigram.util.json

import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.JsonToken
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import com.fasterxml.jackson.databind.JsonMappingException
import ski.gagar.vxutil.vertigram.types.attachments.Attachment
import ski.gagar.vxutil.vertigram.types.attachments.UrlAttachment

internal class AttachmentDeserializer : JsonDeserializer() {
    override fun deserialize(parser: JsonParser, ctxt: DeserializationContext): Attachment =
        when (parser.currentToken) {
            JsonToken.VALUE_STRING -> UrlAttachment(parser.valueAsString)
            else -> {
                throw JsonMappingException.from(parser, "attachment should be string")
            }
        }

    override fun handledType(): Class = Attachment::class.java
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy