No-args constructor for class does not exist. Register an InstanceCreator with G

有时候我们在使用Googel官方的json解析包时,如果自己的实体类中出现代参的构造函数,如;


[*]public class InformationSummary {
[*] /**
[*] * id
[*] */
[*] public String id;
[*]
[*] /**
[*] * 栏目名称
[*] */
[*] public String name;
[*]
[*] /**
[*] * 栏目图片
[*] */
[*] public String picture;
[*]
[*] /**
[*] * 栏目内容
[*] */
[*] public String content;
[*]
[*] /**
[*] * 新闻头条id
[*] */
[*] public String newsId;
[*]
[*] /**
[*] * 子业务编码
[*] */
[*] public String subCode;
[*]
[*]
[*]
[*] public InformationSummary(String id, String name, String picture, String content) {
[*] super();
[*] this.id = id;
[*] this.name = name;
[*] this.picture = picture;
[*] this.content = content;
[*] }

如果这样写的话,有时候会报这样的错误;

[color=red][b]06-26 17:08:59.723: W/System.err(4724): java.lang.RuntimeException: No-args constructor for class com.funo.health.bean.business.InformationSummary does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
06-26 17:08:59.723: W/System.err(4724): at com.google.gson.MappedObjectConstructor.constructWithNoArgConstructor(MappedObjectConstructor.java:64)[/b][/color]
简单认识就是我们自己写了构造函数后,本身自带的无参就会忽略,但是json.jar包中的Gson,需要!简单方法就是加上无参数构造函数!


参考:
[url]http://stackoverflow.com/questions/3294829/java-reading-json-null[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值