jfinal3.2或jfinal3.3 json数据如何转换成自动生成带set get方法的model

@JFinal 波总, jfinal3.3是否支持JSON转javabean(即自动生成带get set方法的model),比如:String paraJson = HttpKit.readData(getRequest());
SaleClientele vo = JSON.parseObject(paraJson, SaleClientele.class); 目前3.2不支持,json转生成baseMode,即javabean model,值为空;如果转为换为自己定义的javabean,肯定没有问题。json转换成自动生成javabean model,目前没有找到好的解决方法,请问波总有好的解决办法吗?请赐教,谢谢

评论区

JFinal

2017-12-13 22:49

早就可以了: User user = FastJson.getJson().parse(paraJson, User.class);

danish001

2017-12-13 23:27

@JFinal 多谢波总,我试下

danish001

2017-12-13 23:49

@JFinal 我这还是不能转,转换出的结果是:{} 测试样例:String pojson = FastJson.getJson().toJson(dicBusiness);//dicBusiness对象转换为json串:{"id":30,"name":"男","pid":0,"type":"XB"}
DicBusiness dic = FastJson.getJson().parse(pojson, DicBusiness.class);//再把json串({"id":30,"name":"男","pid":0,"type":"XB"})转换为DicBusiness对象,对象debug为{};

样例的model对象:
public class DicBusiness extends BaseDicBusiness {
public static final DicBusiness dao = new DicBusiness().dao();
}
以及对象继承的BaseDicBusiness代码:
public abstract class BaseDicBusiness> extends Model implements IBean {

public M setId(java.lang.Long id) {
set("id", id);
return (M)this;
}

public java.lang.Long getId() {
return getLong("id");
}

public M setPid(java.lang.Long pid) {
set("pid", pid);
return (M)this;
}

public java.lang.Long getPid() {
return getLong("pid");
}

public M setType(java.lang.String type) {
set("type", type);
return (M)this;
}

public java.lang.String getType() {
return getStr("type");
}

public M setName(java.lang.String name) {
set("name", name);
return (M)this;
}

public java.lang.String getName() {
return getStr("name");
}

public M setSort(java.lang.Integer sort) {
set("sort", sort);
return (M)this;
}

public java.lang.Integer getSort() {
return getInt("sort");
}

public M setRemark(java.lang.String remark) {
set("remark", remark);
return (M)this;
}

public java.lang.String getRemark() {
return getStr("remark");
}

}

danish001

2017-12-14 00:38

@JFinal json转换成DicBusiness对象为空

akak

2017-12-14 15:27

Jfinal3.3,我测试了,直接转model肯定是不行的。我的处理办法是,
String jsonString = HttpKit.readData(getRequest());
JSONObject dataMap = JSONObject.parseObject(jsonString);
Student model = new Student ();
model._setAttrs(dataMap.getJSONObject("student").toJavaObject(Map.class));
不知道还有没有更好的方式呢?

热门反馈

扫码入社