Lau*_*uri 25
Gson使用GWT中不支持的Java功能,例如反射.因此,不可能在GWT客户端代码中使用Gson.
Bor*_*ich 15
不完全是你写的,但我猜你的意思是如何在GWT代码中序列化/反序列化JSON?
在GWT 2.1.1中,您可以使用GWT AutoBean框架
看到文章底部有这个神奇的代码......
String serializeToJson(Person person)
{
// Retrieve the AutoBean controller
AutoBean<Person> bean = AutoBeanUtils.getAutoBean(person);
return AutoBeanCodex.encode(bean).getPayload();
}
Person deserializeFromJson(String json)
{
AutoBean<Person> bean = AutoBeanCodex.decode(myFactory, Person.class, json);
return bean.as();
}
Run Code Online (Sandbox Code Playgroud)
serializeToJson()对我来说很好,即使是继承Person的实例但我没有尝试deserializeFromJson ...
| 归档时间: |
|
| 查看次数: |
12621 次 |
| 最近记录: |