带有POJO类而不是接口的GWT AutoBean [英] GWT AutoBean with POJO class instead of interface

查看:174
本文介绍了带有POJO类而不是接口的GWT AutoBean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能为我的问题提出一个简单的解决方案。

I'm hoping someone can suggest a simple solution to my problem.

我有一个POJO,比如说:

I have a POJO, say:

public class Person
{
    private String name;
    public String getName(){ return name; }
    public void setName(String name){ this.name = name; }
}

我想使用GWT的AutoBean功能来序列化/反序列化这个bean到JSON,但AutoBean需要一个接口:

I'd like to use GWT's AutoBean functionality to serialize / deserialize this bean to JSON, but AutoBean expects an interface:

public interface Person
{
    public String getName();
    public void setName(String name);
}

我有一个AutoBeanFactory设置:

I have an AutoBeanFactory setup:

public interface PersonFactory extends AutoBeanFactory
{
    AutoBean<Person> person();
}

使用工厂和Person界面,我可以反序列化一个JSON Person :

Using the factory and the Person interface, I am able to deserialize a JSON Person:

PersonFactory personFactory = GWT.create(PersonFactory.class);
AutoBean<Person> autoBeanPerson = AutoBeanCodex.decode(personFactory, Person.class, jsonObject.toString());
Person person = autoBeanPerson.as();

但是,如果我将Person接口替换为Person类,则会收到一个AutoBeanFactoryGenerator异常,其中声明: com.xxx.xxx.Person不是接口。

However, if I replace the Person interface with the Person class, I receive an AutoBeanFactoryGenerator exception that states: "com.xxx.xxx.Person is not an interface".

如何使用AutoBean序列化/反序列化与我的简单POJO?

How can I use AutoBean serialization / deserialization with my simple POJO?

推荐答案

你根本就做不到。 AutoBean生成接口的轻量级优化实现;它显然不能为班级做到这一点。这是设计

You simply can't. AutoBean generates lightweight, optimized implementations of the interfaces; it obviously cannot do this for classes. This is by design.

这篇关于带有POJO类而不是接口的GWT AutoBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆