I have the following mapping on my spring mvc controller:
@RequestMapping(value = "/servers", method = RequestMethod.GET)
public @ResponseBody Server getServers(@RequestParam(value="password", required=false) String password)
{
Server server = new Server();
server.setIpaddress("192.168.0.4");
server.setServername("serverOne");
List<Service> list = new ArrayList<Service>();
Service s1 = new Service();
s1.setServiceName("telnet");
s1.setServicePort(21);
list.add(s1);
s1= new Service();
s1.setServiceName("SSH");
s1.setServicePort(22);
list.add(s1);
server.SetServices(list);
return server;
}
It should return a server class in json , with one filled property matching List but is doesn't show anything. This are the involved classes:
Class Server:
package es.landesoft.mvctesting.JavaBeans;
import java.util.List;
public class Server {
private String ipaddress;
private String serverName;
private List<Service> services;
public void setIpaddress(String value)
{
this.ipaddress = value;
}
public String getIpAddress()
{
return this.ipaddress;
}
public void setServername (String value)
{
this.serverName= value;
}
public String getServername()
{
return this.serverName;
}
public void SetServices(List<Service> services)
{
this.services= services;
}
public List<Service> GetServices()
{
return this.services;
}
}
Class service:
package es.landesoft.mvctesting.JavaBeans;
public class Service
{
private String serviceName;
private int servicePort;
public void setServiceName(String value)
{
this.serviceName= value;
}
public String getServiceName(){
return this.serviceName;
}
public void setServicePort(int value)
{
this.servicePort=value;
}
public int getServicePort()
{
return this.servicePort;
}
}
The Json Output is:
{"servername":"serverOne","ipAddress":"192.168.0.4"}
No trace of the List property. What am I doing wrong.