I use AutoBean to code/decode data to JSON and that was all right in previous GWT versions. In my opinion AutoBean is very good and convenient tool to deal with JSON. Since GWT ver.2.4.0 this functionality has changed and I spent some time to restore it in my code. But only one part stays still unfixed - annotation @PropertyName. This annotation is used to add an "alias" to properties. It saves a lot of network traffic. And now it throws an exception. The code example is below:
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...
}
Then I try to decode this to JSON in this way:
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
This piece of code worked perfectly in legacy code. But now (in GWT 2.4.0) I get an exception:
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)
If I remove the @PropertyName from my interface, then the exception won't occur.
I still waiting, that the official documentation will be updated, but it still stays with old code examples.
Can someone help me to solve this issue? Thank you for advice.
I use GWT ver. 2.4.0, GAE ver. 1.6.1.
I needed to put @PropertyName("XXXX") on my set methods as well. Give it a try.