I meet exceptions when I deserialize Kotlin data classes with following code:
data class DataClassSimple(val a : Int, val b : Int)
@Test
fun test2() {
val dts = DataClassSimple(1,2)
val jsons = JSON.toJSONString(dts)
println(jsons)
val clzs = DataClassSimple::class
println(clzs.javaObjectType)
val dt2 = JSON.parseObject(jsons,clzs.javaObjectType)
println(dt2)
}
Exception is listed below:
com.alibaba.fastjson.JSONException: default constructor not found. class com.example.HelloTest$DataClassSimple
at com.alibaba.fastjson.util.JavaBeanInfo.build(JavaBeanInfo.java:465)
at com.alibaba.fastjson.util.JavaBeanInfo.build(JavaBeanInfo.java:211)
at com.alibaba.fastjson.parser.ParserConfig.createJavaBeanDeserializer(ParserConfig.java:643)
at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:560)
at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(ParserConfig.java:373)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:651)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:365)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:269)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:488)
at com.example.HelloTest.test2(HelloTest.kt:29)
Environment:
- Kotlin 1.2.10
- JDK 1.8
- fastjson 1.2.44
Thank you!
4条答案
按热度按时间flvlnr441#
@wenshao Can you have a look on this ?
jbose2ul2#
I have the same problem too
aor9mmx13#
same problem here too. Creating empty constructors doesn't help
z9smfwbn4#
so, how to fix this bug? use gson ?