SpringSource/spring-test-mvc — Issue #24: BeanInstantiationException with multiple params
Author: aksharp
Created: 2012-02-12 01:50:09+00:00
State: open

Fails with BeanInstantiationException when passing JSON string which maps to DTO with MORE THAN ONE parameter. See example below:

In example below, passing Command command = new Command("1","2"); will fail
However passing Command command = new Command("1"); (given that controller action expects only one parameter and DTO only has one parameter) would be ok

This FAILS:

// Test
@Test
public void shouldMap() throws Exception {
Command command = new Command("1","2");
String jsonCommand = new Gson().toJson(command);
standaloneSetup(controller).build()
.perform(post("/go").param("command", jsonCommand))
.andExpect(status().isOk());
}

// Controller Action

@RequestMapping(value="/go", method=RequestMethod.POST)
public void addDestination(Command command) {
String var1 = command.getVar1();
String var2 = command.getVar2();
}

// DTO
public class Command {

private final String var1;
private final String var2;

public Command(String var1, String var2){
this.var1 = var1;
this.var2 = var2;

}

public String getVar1() {
return var1;
}

public String getVar2() {
return var2;
}
}