I'm developing a Spring MVC REST application. I made a few simple controller like this:
@Controller
@RequestMapping("/agents")
public class AgentsController {
@Autowired
AgentsRepository agentsRepository;
@RequestMapping(value="/{id}",method=RequestMethod.GET)
public @ResponseBody Agents getAgents(@PathVariable Long id){
Agents agents = agenteRepository.findOne(id);
return agent;
}
@RequestMapping(method=RequestMethod.GET)
public @ResponseBody List<Agents> getAllAgents(){
return agentsRepository.findAll();
}
}
The agent class is annotated in this way:
@XmlRootElement
@Entity
public class Agents implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long idAgents;
private String name;
private String surname;
Now the problem is the following, when I try to do a http get with (host+post/myapplication/agents/1) everything work and I get inside my browser the xml structure, instead when I do (host+post/myapplication/agents) I don't get all agent list in a xml structure, but I get the toString of the collection.
What am I doing wrong?