PDA

View Full Version : Spring MVC Controllers that are only deal with Rest + JASON objects.



channaitfac
Sep 26th, 2011, 12:22 AM
I want do design my web application core part (skeleton) with Spring MVC with Rest + JASON, that mean I want to develop several clients (stubs) which are communicate with core (skeleton) only via Rest + JSON. According to this requirements I wan to code all my Spring related controllers to communicate via only with JASON objects that mean I want not rerun any JPS view with models (ViewResolver should not deal with jsp resources).

I have found some examples, but on those examples Spring controllers are return both jsp resources and JASON objects. Can any one please specify some sample project or mechanism, Spring Controllers that are only deal with JASON objects.

Thanks

venosov
Mar 24th, 2012, 07:27 AM
Hi, here you have an example:



@RequestMapping("/jsontournament")
public String getJSON(Model model) {
List<TournamentContent> tournamentList = new ArrayList<TournamentContent>();
tournamentList.add(TournamentContent.generateConte nt("FIFA",
new Date(),"World Cup","www.fifa.com/worldcup/"));
tournamentList.add(TournamentContent.generateConte nt("FIFA",
new Date(),"U-20 World Cup","www.fifa.com/u20worldcup/"));
tournamentList.add(TournamentContent.generateConte nt("FIFA",
new Date(),"U-17 World Cup","www.fifa.com/u17worldcup/"));
tournamentList.add(TournamentContent.generateConte nt("FIFA",
new Date(),"Confederations Cup","www.fifa.com/confederationscup/"));
model.addAttribute("feedContent",tournamentList);
return "jsontournamenttemplate";
}




<bean id="jsontournamenttemplate"
class="org.springframework.web.servlet.view.json.MappingJ acksonJsonView"/>


You can access a URL in the form http://[host_name]/jsontournament.json