Kotlin reported an error jsonexception using fastjason: default constructor not found

Fastjson version number: implementation ‘com. Alibaba: fastjson: 1.2.69’

Error message:

com.alibaba.fastjson.JSONException: default constructor not found

User.kt

data class User(var name: String, var age: Int) {
}

Problem analysis:

The results found on the Internet are that there are no parameter free construction methods for object classes, so add
user.kt

data class User(var name: String, var age: Int) {
    constructor() : this("", 0)
}

However, the error is still reported. By understanding the fastjason source code, it turns out that it needs to get the kotlin construction method through reflection. To use kotlin reflection, it needs to rely on [kotlin reflect]:

implementation 'org.jetbrains.kotlin:kotlin-reflect:1.5.20'

After the above dependencies are added, even if there is no parameter free construction method, it can be used normally through the test

Read More: