I need to execute this URL: http://localhost:8080/FitiProject/student and the response needs to be a json string containing the data of a Student
object.
Here is my code:
package spring.controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import model.Student;
@Controller
public class PruebaController {
@RequestMapping("/student")
public @ResponseBody Student getStudent(){
return new Student(2, "h");
}
}
This is Student.java
package model;
public class Student {
private int edad;
private String nombre;
public Student(int edad, String nombre) {
super();
this.edad = edad;
this.nombre = nombre;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
}
When I do a GET request on the URL, I don't get a JSON response instead I get a 406 error code. How can I solve this?
I'm using Jackson 1.9 and Spring 4.1.
type Informe de estado
mensaje
descripción El recurso identificado por este requerimiento sólo es capaz de generar respuestas con características no aceptables con arreglo a las cabeceras "accept" de requerimiento.
– Federico Portillo Feb 01 '16 at 15:30