Java GWT AutoBean:annotation@PropertyName不再工作

Java GWT AutoBean:annotation@PropertyName不再工作,java,gwt,annotations,autobean,Java,Gwt,Annotations,Autobean,我习惯于将数据编码/解码为JSON,这在以前的GWT版本中是正确的。在我看来,AutoBean是处理JSON的非常好和方便的工具。自从GWT版本2.4.0以来,这个功能已经改变了,我花了一些时间在代码中恢复它。但只有一部分仍然没有固定-annotation@PropertyName。此注释用于向属性添加别名。它节省了大量的网络流量。现在它抛出了一个异常。代码示例如下所示: import com.google.web.bindery.autobean.shared.AutoBean.Propert

我习惯于将数据编码/解码为JSON,这在以前的GWT版本中是正确的。在我看来,AutoBean是处理JSON的非常好和方便的工具。自从GWT版本2.4.0以来,这个功能已经改变了,我花了一些时间在代码中恢复它。但只有一部分仍然没有固定-annotation@PropertyName。此注释用于向属性添加别名。它节省了大量的网络流量。现在它抛出了一个异常。代码示例如下所示:

import com.google.web.bindery.autobean.shared.AutoBean.PropertyName;

public interface IPersonInfo {

    // Name
    @PropertyName("n")
    public String getName();
    public void setName(String name);

    // Surname
    @PropertyName("s")
    public String getSurname();
    public void setSurname(String surname);

    // other properties...
}
然后我尝试用以下方式将其解码为JSON:

AutoBean<IPersonInfo> user = factory.user();

// clone the userDto (it's a new way to clone an object in ver 2.4.0
// instad of deprecated clone() method)
Splittable data = AutoBeanCodex.encode(user);
IPersonInfo userDto = AutoBeanCodex.decode(factory, IPersonInfo.class, data).as();

userDto.setName("Name");
userDto.setSurname("Surname");
//... other properties
如果从接口中删除@PropertyName,则不会发生异常

我仍然在等待,官方文档将被更新,但它仍然停留在旧的代码示例中

有人能帮我解决这个问题吗?谢谢你的建议


我使用GWT版本。2.4.0,GAE版本。1.6.1.

我还需要在我的set方法中添加@PropertyNameXXXX。试试看。

我还需要在我的set方法中添加@PropertyNameXXXX。试试看。

谢谢!解决方法很简单。。。正如你所悲伤的,我把注释同时放在setter和getter上,它就工作了!因此,不是//Name@PropertyNamen公共字符串getName;public void setNameString名称;我这样说//Name@PropertyNamen公共字符串getName@PropertyNamen公共void setNameString名称;非常感谢。解决方法很简单。。。正如你所悲伤的,我把注释同时放在setter和getter上,它就工作了!因此,不是//Name@PropertyNamen公共字符串getName;public void setNameString名称;我这样说//Name@PropertyNamen公共字符串getName@PropertyNamen公共void setNameString名称;
java.lang.IllegalArgumentException: name
    at com.google.web.bindery.autobean.shared.impl.AutoBeanCodexImpl.doCoderFor(AutoBeanCodexImpl.java:524)
    at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.setProperty(AbstractAutoBean.java:276)
    at com.google.web.bindery.autobean.vm.impl.ProxyAutoBean.setProperty(ProxyAutoBean.java:253)
    at com.google.web.bindery.autobean.vm.impl.BeanMethod$3.invoke(BeanMethod.java:103)
    at com.google.web.bindery.autobean.vm.impl.SimpleBeanHandler.invoke(SimpleBeanHandler.java:43)
    at $Proxy74.setName(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:104)
    at com.google.web.bindery.autobean.vm.impl.ShimHandler.invoke(ShimHandler.java:81)
    at $Proxy74.setName(Unknown Source)