I have the mapper below that’s working fine, but I was wondering if there’s any way to define once and reuse the duplicate mappings on remoteToNewLocalApp and remoteToLocalAppUpdate.
@Mapper
interface AppMapper {
@Mapping(target = "appId", source = "atemsPackage.appId", defaultExpression = "java(packageId)")
@Mapping(target = "appOnRemote", constant = "true")
fun remoteToNewLocalApp(atemsPackage: AtemsPackage, packageId: String): LocalApp
@Mapping(target = "appId", source = "atemsPackage.appId", defaultExpression = "java(packageId)")
@Mapping(target = "appOnRemote", constant = "true")
fun remoteToLocalAppUpdate(atemsPackage: AtemsPackage, packageId: String): LocalAppRemoteUpdate
companion object {
val INSTANCE: AppMapper =
Mappers.getMapper(AppMapper::class.java)
}
}
UPDATE
@Mapper
interface AppMapper {
@Mapping(target = "appId", source = "atemsPackage.appId", defaultExpression = "java(packageId)")
@Mapping(target = "appOnRemote", constant = "true")
fun remoteToNewLocalApp(atemsPackage: AtemsPackage, packageId: String): LocalApp
@InheritConfiguration(name = "remoteToNewLocalApp")
fun remoteToLocalAppUpdate(atemsPackage: AtemsPackage, packageId: String): LocalAppRemoteUpdate
companion object {
val INSTANCE: AppMapper =
Mappers.getMapper(AppMapper::class.java)
}
}
>Solution :
you can use @InheritConfiguration on the second mapper method.