Professional Documents
Culture Documents
Springrest:: Jersey
Springrest:: Jersey
Springrest:: Jersey
@RestController
return listofCountries;
}}
XML format
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class HelloWorld {
@XmlElement
private String message;
}
@XmlRootElement – specifies the root tag of each HelloWorld record in xml.
RestTemplate: http://javainsimpleway.com/spring-resttemplate-crud-operations-with-json/
Jersey:
Jersey internally uses Jackson for Json Handling, so it will be used to marshal pojo
objects to JSON
@Path("/countries")
public class CountryRestService {
@GET
@Path("{id: d+}")
@Produces(MediaType.APPLICATION_JSON)
public Country getCountryById(@PathParam("id") int id)
{
List listOfCountries = new ArrayList();
listOfCountries=createCountryList();
for (Country country: listOfCountries) {
if(country.getId()==id)
return country;
}
return null;
}
@Path
@PathParam
@QueryParam
@MatrixParam
@HeaderParam
@CookieParam