Just had the same problem.... Seems to be a bug in the AutoBean List 
implementation

I solved it by simply:

autoBean.setList(new ArrayList<Type>(autoBean.getList));

On Tuesday, January 31, 2012 10:51:17 PM UTC+1, Cypher wrote:
>
> I am having problems modifying a list property on an AutoBean 
> deserialized from JSON with AutoBeanCodex.  When I call 
> List<>.add(position, value) it appears to be overwriting the value at 
> that position instead of shifting values right to make room for the 
> new item. 
>
> Here's a JUnit test that demonstrates the behavior I'm seeing: 
>
> public class AutoBeanListTest extends GWTTestCase { 
>
>         @Override 
>         public String getModuleName() { 
>                 return "com.xxx.AutoBeanListTest"; 
>         } 
>
>         @Test 
>         public void testDirectInsert() { 
>                 MyBeanFactory factory = GWT.create(MyBeanFactory.class); 
>                 MyBean bean = factory.myBean().as(); 
>                 bean.setValues(new ArrayList<String>()); 
>                 bean.getValues().add("A"); 
>                 bean.getValues().add("C"); 
>
>                 assertEquals(2,bean.getValues().size()); 
>
>                 bean.getValues().add(1,"B"); 
>
>                 assertEquals(3,bean.getValues().size()); // this one works 
>                 assertEquals("A", bean.getValues().get(0)); 
>                 assertEquals("B", bean.getValues().get(1)); 
>                 assertEquals("C", bean.getValues().get(2)); 
>         } 
>
>         @Test 
>         public void testSerializeInsert() { 
>                 MyBeanFactory factory = GWT.create(MyBeanFactory.class); 
>                 MyBean bean = factory.myBean().as(); 
>                 bean.setValues(new ArrayList<String>()); 
>                 bean.getValues().add("A"); 
>                 bean.getValues().add("C"); 
>
>                 assertEquals(2,bean.getValues().size()); 
>
>                 String json = 
> AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(bean)).getPayload(); 
>                 bean = AutoBeanCodex.decode(factory, MyBean.class, 
> json).as(); 
>
>                 assertEquals(2,bean.getValues().size()); 
>
>                 bean.getValues().add(1,"B"); 
>
>                 assertEquals(3,bean.getValues().size()); // this one FAILS 
>                 assertEquals("A", bean.getValues().get(0)); 
>                 assertEquals("B", bean.getValues().get(1)); 
>                 assertEquals("C", bean.getValues().get(2)); 
>         } 
>
>         public interface MyBeanFactory extends AutoBeanFactory { 
>                 AutoBean<MyBean> myBean(); 
>                 AutoBean<MyBean> myBean(MyBean myBean); 
>         } 
>
>         public interface MyBean { 
>                 List<String> getValues(); 
>                 void setValues(List<String> values); 
>         } 
> } 
>
> The first test case (which modifies a list that I create and put into 
> the bean) works as I expect, but the second test (which modifies the 
> list returned from deserialization) does not.  After the insert, the 
> list still has only two values in it, and the second one has been 
> replaced by the value I inserted. 
>
> Am I doing something wrong?  Is this an issue in the underlying code? 
>
> I can't help but notice that the SplittableList class uses the same 
> implementation for set() and add().  That doesn't seem right to me, 
> but I assume I must be missing something. 
>
> James

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to