我使用Kotlin/Springboot,并希望使用ModelMapper
映射到数据类。我想将account:balance:amount:int
映射到accountdto:balance:float
来自:
data class Account(
val id: String,
var balance: Amount
)
data class Amount(var value: Int)
data class AccountDto(
var id: String,
var balance: Float?)
val modelMapper = ModelMapper()
modelMapper.addMappings(object : PropertyMap<Account, AccountDto>() {
override fun configure() {
map(source.balance.value / 100f, destination.balance)
}
})
但我有这样的错误:
Caused by: org.modelmapper.ConfigurationException: ModelMapper configuration errors:
1) Cannot map final type ....accounts.Account.
2) Cannot map final method ....accounts.Account.getBalance().
3) Cannot map final type ....accounts.Amount.
4) Cannot map final method ....accounts.Amount.getValue().
5) Cannot map final type ....account.dto.AccountDto.
6) Cannot map final method ....account.dto.AccountDto.getBalance().
我现在不知道。
将val
更改为var
data class Account(
val id: String,
var balance: Amount
)