I found that numbers in kotlin is not serializable.
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>
}
I get an error when I try to compile this code, because kotlin.Long is not Serializable:
Error:(14, 72) Kotlin: Type argument is not within its bounds: should be subtype of 'java.io.Serializable?'
I get the same error when I try to use 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>
}
Warning:(14, 72) Kotlin: This class shouldn't be used in Kotlin. Use kotlin.Long instead.
Error:(14, 72) Kotlin: Type argument is not within its bounds: should be subtype of 'java.io.Serializable?'
As-of Kotlin 1.0 Beta 1 primitive types are serializable:
Int is Serializable
Now the type Int and other basic types are Serializable on the JVM. This should help many frameworks.
from: http://blog.jetbrains.com/kotlin/2015/10/kotlin-1-0-beta-candidate-is-out/
Therefore you no longer have any issues.
I found workaround of this problem:
Device.kt:
package test.domain
import javax.persistence.*
Entity public class Device {
public EmbeddedId var id: DeviceId = DeviceId()
public var name: String = ""
...
}
Embeddable public class DeviceId: Serializable {
public GeneratedValue var id: Long = -1
}
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, DeviceId?> {
public fun findByName(Param("name") name: String): List<Device>
}
This use-case works fine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With