kotlin の数値はシリアライズできないことがわかりました。
- 最初の問題
Device.kt:
package test.domain
import javax.persistence.*
Entity public class Device {
public Id GeneratedValue var id: Long = -1
public var name: String = ""
...
}
DeviceRestRepository.kt:
package test.domain
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.data.repository.query.Param
import org.springframework.data.rest.core.annotation.RepositoryRestResource
RepositoryRestResource(collectionResourceRel = "device", path = "device")
public trait DeviceRestRepository : PagingAndSortingRepository<Device, Long?> {
public fun findByName(Param("name") name: String): List<Device>
}
kotlin.LongはSerializableではないため、このコードをコンパイルしようとするとエラーが発生します。
エラー:(14、72) Kotlin:型引数がその境界内にありません:「java.io.Serializable?」のサブタイプにする必要があります
- 第二の問題
java.lang.Longを使用しようとすると、同じエラーが発生します。
DeviceRestRepository.kt:
package test.domain
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.data.repository.query.Param
import org.springframework.data.rest.core.annotation.RepositoryRestResource
RepositoryRestResource(collectionResourceRel = "device", path = "device")
public trait DeviceRestRepository : PagingAndSortingRepository<Device, java.lang.Long?> {
public fun findByName(Param("name") name: String): List<Device>
}
警告:(14, 72) Kotlin: このクラスは Kotlin では使用しないでください。代わりに kotlin.Long を使用してください。
エラー:(14、72) Kotlin:型引数がその境界内にありません:「java.io.Serializable?」のサブタイプにする必要があります