سؤال

I am using Autobean framework to encode/decode JSON in my GWT application. It works in cases with the interfaces having getters and setters. But is there any way to do it some other way to do this without specifying a setThisCollectionProperty instead using an addToThisCollectionProperty method?

For example, I have an interface IPerson like this:

public interface IPerson {
       public String getName();
       public void setName(String name);

       public int getAge();
       public void setAge(int age);

       public List<String> getIds();
       public void addId(String id);
}

BeanFactory is like this:

public interface BeanFactory extends AutoBeanFactory {

    public AutoBean<IPerson> person();

    public AutoBean<IPerson> person(IPerson person);


}

and in Person class which implements IPerson,

public class Person implements IPerson {
       private String name;
       private List<String> ids;
       ...

       public List<String> getIds() {
              return ids;
       }

       public void addId(String id) {
              ...
              ids.add(id);
       }
}

It works if the addId(String id) is replaced with setIds(List<String> ids). Otherwise the following error is shown:

The com.mycompany.jsonsample.beans.IPerson parameterization is not simple, but the person method does not provide a delegate

Is it possible to encode/decode without a set method?

هل كانت مفيدة؟

المحلول

AutoBean manages all getters and setters, and only getters and setters. For any other method, you have to use a category.

Using a category, you could thus implement addId(…) as getIds().add(…), or possibly directly call addIds on the underlying object if the AutoBean is a wrapper.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top