spring – kotlin中的数字不可序列化

前端之家收集整理的这篇文章主要介绍了spring – kotlin中的数字不可序列化前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我发现kotlin中的数字不可序列化.@H_403_2@

>第一个问题@H_403_2@

Device.kt:@H_403_2@

@H_403_2@

package test.domain

import javax.persistence.*

Entity public class Device {
    public Id GeneratedValue var id: Long = -1
    public var name: String = ""
    ...
}

DeviceRestRepository.kt:@H_403_2@

@H_403_2@

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

我尝试编译此代码时出错,因为kotlin.Long不是Serializable:@H_403_2@

@H_403_2@

Error:(14,72) Kotlin: Type argument is not within its bounds: should
be subtype of ‘java.io.Serializable?’@H_403_2@

>第二个问题@H_403_2@

我尝试使用java.lang.Long时遇到同样的错误:@H_403_2@

DeviceRestRepository.kt:@H_403_2@

@H_403_2@

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",java.lang.Long?> {
    public fun findByName(Param("name") name: String): List

Warning:(14,72) Kotlin: This class shouldn’t be used in Kotlin. Use
kotlin.Long instead. @H_403_2@

Error:(14,72) Kotlin: Type argument is not
within its bounds: should be subtype of ‘java.io.Serializable?’@H_403_2@

最佳答案
至于Kotlin 1.0 Beta 1原始类型是可序列化的:@H_403_2@

@H_403_2@

Int is Serializable@H_403_2@

Now the type Int and other basic types are Serializable on the JVM. This should help many frameworks.@H_403_2@

从:
http://blog.jetbrains.com/kotlin/2015/10/kotlin-1-0-beta-candidate-is-out/@H_403_2@

因此,您不再有任何问题.@H_403_2@

猜你在找的Spring相关文章