Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. NullPointerException when using GWT's AutoBean deserialization with HashMap
  2. public class AutoBeanTest {
  3.  
  4.     @Test
  5.     public void test() throws Exception {
  6.         MyFactory myFactory = AutoBeanFactorySource.create(MyFactory.class);
  7.  
  8.         Options options = myFactory.options().as();
  9.         options.setMyInt(5);
  10.         HashMap<Double, Boolean> map = newHashMap();
  11.         map.put(8.0, true);
  12.         map.put(9.1, false);
  13.  
  14.         options.setMyMap(map);
  15.  
  16.         Options deserialized = AutoBeanCodex.decode(myFactory, Options.class, AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(options)).getPayload()).as();
  17.         assertEquals(deserialized.getMyInt(),5);
  18.         assertTrue(options.getMyMap().containsKey(8d));
  19.         assertTrue(deserialized.getMyMap().containsKey(8d));
  20.     }
  21.  
  22.     public interface MyFactory extends AutoBeanFactory {
  23.         AutoBean<Options> options();
  24.     }
  25.  
  26.     public interface Options {
  27.  
  28.         public int getMyInt();
  29.  
  30.         void setMyInt(int myInt);
  31.  
  32.         Map<Double, Boolean> getMyMap();
  33.  
  34.         void setMyMap(Map<Double, Boolean> myMap);
  35.     }
  36. }