'Spring WebFlow collection binding issue - EvaluationException

I'm using Spring WebFlow with this POST form data:

attr1: Some value
attr2: Some date
collection[0].id: 123
collection[0].json: {..json...}
collection[1].id: 321
collection[1].json: {...other json...}
_eventId_xyz: 

And i'm binding this data to

public class FormData implements Serializable {

  private static final long serialVersionUID = 1L;

  private String attr1;

  private LocalDate attr2;

  private List<MyCollectionItem> collection = new AutoPopulatingList<>(MyCollectionItem.class);
}


public class MyCollectionItem implements Serializable {

  private static final long serialVersionUID = 1L;

  private Integer id;

  private String json;
}

Binding works until I added collection to my form. Now with added form data backend returns 302 Not Found and redirects me back to same step.

Edit:

I discovered that the problem is present when I have custom object (MyCollectionItem) in my collection - when using String/Integer binding works as expected.

Edit 2: Exception message is A BeansException occurred setting the value of expression 'collection[0].id' on context [...FormClass] to [123]

Invalid property 'collection[0]' of bean class [...FormClass]: Index of out of bounds in property path 'collection[0]'



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source