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

dev.morphia.mapping.conventions.KotlinDelegatedPropertiesDiscovery.kt Maven / Gradle / Ivy

There is a newer version: 2.4.14
Show newest version
package dev.morphia.mapping.conventions

import dev.morphia.mapping.Mapper
import dev.morphia.mapping.codec.pojo.EntityModelBuilder
import kotlin.reflect.KMutableProperty
import kotlin.reflect.KProperty

class KotlinDelegatedPropertiesDiscovery : MorphiaConvention {
    @Suppress("UNCHECKED_CAST")
    override fun apply(mapper: Mapper, builder: EntityModelBuilder) {
        val field =
            builder.type().declaredFields.firstOrNull { it.name == "\$\$delegatedProperties" }
        if (field != null) {
            field.trySetAccessible()
            for (kProperty in field.get(builder.type()) as Array>) {
                builder
                    .propertyModelByName("${kProperty.name}\$delegate")
                    .name(kProperty.name)
                    .discoverMappedName()
                    .accessor(ReadWritePropertyAccessor(kProperty as KMutableProperty<*>))
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy