We had a similiar issue with binding post data to a list inside a command. Our workaround that worked was to define a default value for collection elements:
class MyCommand {
List<MyClass> items= [].withLazyDefault {
new MyClass()
}
}
After that the post data was correctly bound to the list. I think the reason is that Groovy ignores the generic type parameter of the list and does not know which object to instantiate at runtime.
I'am not sure if this works in your case but it might be worth a try
Update:
I used this a few minutes ago:
public static class MyCommand {
String foo
List<Bar> bars
public String toString() {
return "foo: " + foo + ", bars: " + bars
}
}
public static class Bar {
String baz
}
controller method:
def test() {
println new MyCommand(request.JSON)
}
I posted some json using jquery:
$.ajax({
type: "POST",
url: '...',
data: JSON.stringify({
'foo': '12345',
bars: [
{baz: '1'},
{baz: '2'}
]
}),
contentType : 'application/json',
});
The output printed by the controller:
foo: 12345, bars: [[baz:1], [baz:2]]
So it seems to work :o