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

cccev.projection.api.converter.FilePathConverter.kt Maven / Gradle / Ivy

The newest version!
package cccev.projection.api.converter

import cccev.commons.utils.parseJsonTo
import cccev.commons.utils.toJson
import city.smartb.fs.s2.file.domain.model.FilePath
import org.neo4j.driver.Value
import org.neo4j.driver.internal.value.StringValue
import org.springframework.core.convert.TypeDescriptor
import org.springframework.core.convert.converter.GenericConverter

class FilePathConverter: GenericConverter {
    override fun getConvertibleTypes(): MutableSet {
        return mutableSetOf(
            GenericConverter.ConvertiblePair(FilePath::class.java, Value::class.java),
            GenericConverter.ConvertiblePair(Value::class.java, FilePath::class.java)
        )
    }

    override fun convert(source: Any?, sourceType: TypeDescriptor, targetType: TypeDescriptor): Any? {
        return when (source) {
            is FilePath -> StringValue(source.toJson())
            is Value -> source.asString().parseJsonTo(FilePath::class.java)
            else -> null
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy