Eduardo Guardiola
Eduardo Guardiola

Reputation: 117

Can't insert new entry into deserialized AutoBean Map

When i try to insert a new entry to a deserialized Map instance i get no exception but the Map is not modified. This EntryPoint code probes it. I'm doing anything wrong?

public class Test2 implements EntryPoint {

public interface SomeProxy {
    Map<String, List<Integer>> getStringKeyMap();
    void setStringKeyMap(Map<String, List<Integer>> value);
}

public interface BeanFactory extends AutoBeanFactory {
    BeanFactory INSTANCE = GWT.create(BeanFactory.class);

    AutoBean<SomeProxy> someProxy();
}

@Override
public void onModuleLoad() {
    SomeProxy proxy = BeanFactory.INSTANCE.someProxy().as();

    proxy.setStringKeyMap(new HashMap<String, List<Integer>>());
    proxy.getStringKeyMap().put("k1", new ArrayList<Integer>());
    proxy.getStringKeyMap().put("k2", new ArrayList<Integer>());

    String payload = AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(proxy)).toString();
    proxy = AutoBeanCodex.decode(BeanFactory.INSTANCE, SomeProxy.class, payload).as();

    // insert a new entry into a deserialized map
    proxy.getStringKeyMap().put("k3", new ArrayList<Integer>());

    System.out.println(proxy.getStringKeyMap().keySet()); // the keySet is [k1, k2] :-( ¿where is k3? 
}

}

Upvotes: 0

Views: 296

Answers (2)

HenioJR
HenioJR

Reputation: 634

Collection classes such as java.util.Set and java.util.List are tricky because they operate in terms of Object instances. To make collections serializable, you should specify the particular type of objects they are expected to contain through normal type parameters (for example, Map<Foo,Bar> rather than just Map). If you use raw collections or maps you will get bloated code and be vulnerable to denial of service attacks.

Font: http://www.gwtproject.org/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes

Upvotes: 0

checketts
checketts

Reputation: 14963

Shouldn't AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(proxy)).toString(); be getPayLoad()

I'll check the code later, and I don't know if that is causing the issue. But it did stand out as different from my typical approach.

Upvotes: 0

Related Questions