Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

kotlin,反序列化时,没有属性字段的set方法,不执行。求解决 #1462

Closed
sw4655315 opened this issue Sep 8, 2017 · 3 comments
Labels
Milestone

Comments

@sw4655315
Copy link

序列化操作时,想隐藏字段。所以data class里属性设置为serialize =false。

data class ObjectA(
        @JSONField(serialize = false)
        var a:String?=""
){
    fun getB():String? = this.a
    fun setB(v:String){
        this.a = "b"
    }
}

fun testjson3(){
    var a:ObjectA = ObjectA()
    a.a = "c"
    val json:String = JSON.toJSONString(a)
    println(json)
    val obj:ObjectA = JSON.parseObject(json, ObjectA::class.java)
    println(obj)
}

输出结果:

{"b":"c"}
ObjectA(a=null)

toJSONString()的时候,执行了getB()方法。
parseObject()的时候,没有执行setB()这个方法。

使用的fastjson 版本是 1.2.37
kotlin版本是1.1.4-2

在java版本里这样子操作是正常的。kotlin不执行set方法。求解决!

@sw4655315
Copy link
Author

setB() 方法上,加上@JSONField 注解也不行。

@wenshao wenshao added the bug label Sep 24, 2017
@wenshao wenshao added this to the 1.2.39 milestone Sep 24, 2017
wenshao added a commit that referenced this issue Sep 28, 2017
@Ycocol
Copy link

Ycocol commented Sep 28, 2017

oh yeah!it is I need 。

@wenshao
Copy link
Member

wenshao commented Oct 1, 2017

https://github.com/alibaba/fastjson/releases/tag/1.2.39
问题已经修复,请用新版本

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants