-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support no parameter constructor #291
Comments
请问”混淆以后报错“是指? |
说的是 b 不可为null,改成第二种写法就没报这个错了 |
@Nstd 可否提供具体的报错信息以及会报错的原json字符串 |
使用的JSON解析库是 测试对象1: @Keep
class TestBean (
@JSONField(name = "a")
var a: Int = 0,
@JSONField(name = "b")
var b: List<Int> = listOf()
) 测试对象2: @Keep
class TestBean {
@JSONField(name = "a")
var a: Int = 0
@JSONField(name = "b")
var b: List<Int> = listOf()
} 测试数据: var testStr = "{a: 10}"
var j1 = JSON.parseObject(testStr, TestBean::class.java)
var testStr2 = "{a: 11, b: [1, 2, 3]}"
var j2 = JSON.parseObject(testStr2, TestBean::class.java)
var testStr3 = "{a: 12, b: []}"
var j3 = JSON.parseObject(testStr3, TestBean::class.java) 报错日志: Caused by: java.lang.NullPointerException: Attempt to get length of null array
at com.alibaba.fastjson.util.JavaBeanInfo.<init>(SourceFile:135)
at com.alibaba.fastjson.util.JavaBeanInfo.build(SourceFile:897)
at com.alibaba.fastjson.parser.deserializer.JavaBeanDeserializer.<init>(SourceFile:49)
at com.alibaba.fastjson.parser.ParserConfig.createJavaBeanDeserializer(SourceFile:963)
at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(SourceFile:805)
at com.alibaba.fastjson.parser.ParserConfig.getDeserializer(SourceFile:538)
at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(SourceFile:679)
at com.alibaba.fastjson.JSON.parseObject(SourceFile:383)
at com.alibaba.fastjson.JSON.parseObject(SourceFile:287)
at com.alibaba.fastjson.JSON.parseObject(SourceFile:560) |
@xurui1995 请问这个有考虑加入新版本吗? |
@Nstd 小伙子要不要考虑提交一个PR上来?加我微信 |
add new feature: replace constructor parameters by member variables fix #291
Released in 3.7.0 |
如果能更新下 |
人懒了🤣,后面我想想搞个自动化change log吧😁 |
哈哈哈,可以有 |
现在导入的时候设置
Disable Kotlin Data Class
可以生成普通的class,但是混淆以后仍然报错,尝试了一下,发现将构造方法改成无参的,变量都改成成员变量就好了。报错的例子:
改成这样就好了:
所以,希望能增加一个配置:是否以无参构造方式生成成员变量。
The text was updated successfully, but these errors were encountered: