I have the following code:
@Path("alumnos")
public class AlumnosController {
@GET
@Produces("application/json")
public List<Alumno> getAlumnos() {
List<Alumno> alumnos = new ArrayList<Alumno>();
alumnos.add(new Alumno("Javier Octavio", 32));
alumnos.add(new Alumno("Gerardo Anibal", 32));
return alumnos;
}
class Alumno {
private String nombre;
@JsonIgnore
private int edad;
/**
* @param nombre
* @param edad
*/
public Alumno(String nombre, int edad) {
super();
this.nombre = nombre;
this.edad = edad;
}
/**
* @return the nombre
*/
public String getNombre() {
return nombre;
}
/**
* @param nombre
* the nombre to set
*/
public void setNombre(String nombre) {
this.nombre = nombre;
}
/**
* @return the edad
*/
@JsonIgnore
public int getEdad() {
return edad;
}
/**
* @param edad
* the edad to set
*/
public void setEdad(int edad) {
this.edad = edad;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "Alumno [nombre=" + nombre + ", edad=" + edad + "]";
}
}
}
I wish to ignore the age field, I used the JsonIgnore annotation but it does not work when I access the url / students it returns me the json with the age.