package org.wicketTutorial.restexample.resource;
import java.util.ArrayList;
import java.util.List;
import org.wicketTutorial.restexample.domain.PersonPojo;
import org.wicketstuff.rest.annotations.MethodMapping;
import org.wicketstuff.rest.annotations.parameters.RequestBody;
import org.wicketstuff.rest.annotations.parameters.ValidatorKey;
import org.wicketstuff.rest.contenthandling.json.objserialdeserial.GsonObjectSerialDeserial;
import org.wicketstuff.rest.contenthandling.json.webserialdeserial.JsonWebSerialDeserial;
import org.wicketstuff.rest.resource.AbstractRestResource;
import org.wicketstuff.restutils.http.HttpMethod;
public class PersonsRestResource extends AbstractRestResource<JsonWebSerialDeserial> {
private static final long serialVersionUID = 1L;
private final List<PersonPojo> persons = new ArrayList<>();
public PersonsRestResource() {
super(new JsonWebSerialDeserial(new GsonObjectSerialDeserial()));
persons.add(new PersonPojo("Freddie Mercury", "fmercury@queen.com", "Eeehooo!"));
persons.add(new PersonPojo("John Deacon", "jdeacon@queen.com", "bass"));
persons.add(new PersonPojo("Brian May", "bmay@queen.com", "guitar"));
persons.add(new PersonPojo("Roger Taylor", "rtaylor@queen.com", "drum"));
}
@MethodMapping("/persons")
public List<PersonPojo> getAllPersons() {
return persons;
}
@MethodMapping(value = "/persons/{personIndex}", httpMethod = HttpMethod.DELETE)
public void deletePerson(int personIndex) {
}
@MethodMapping(value = "/persons", httpMethod = HttpMethod.POST)
public PersonPojo createPerson(
@ValidatorKey("personValidator") @RequestBody PersonPojo personPojo) {
return personPojo;
}
@Override
protected void onInitialize(JsonWebSerialDeserial objSerialDeserial) {
super.onInitialize(objSerialDeserial);
registerValidator("personValidator", new PersonPojoValidator());
}
}