I’m using @ResponseBody to get the json to Browser.I could get the data,but now if I try getting array of Strings or list of Strings then I get the following
The resource identified by this request is only capable of generating
responses with characteristics not acceptable according to the request
“accept” headers ().
Why the above status?
The following is the Object I’m returning from controller
public class Temp
{
List<String> strArr=new ArrayList<String>();
public Temp()
{
strArr.add("1");
strArr.add("2");
strArr.add("3");
strArr.add("4");
System.out.println("temp="+strArr);
}
}
The following is the controller
@RequestMapping ( value = "/temp.htm" , method = RequestMethod.GET,produces="application/json")
public @ResponseBody Temp getTemp()
{
return new Temp();
}
I could get normal String data but if I try to get array or list of String I get the above status.
Please help
a) You need to set your accept headers to
application/jsonb) Your bean class is not a proper Java bean. You need to expose a getter method:
c) Do you have Jackson on your classpath, and do you have a proper mvc config? In most cases, this will be enough:
(see this section)
d) I’m guessing you have to remove the
@ResponseBodyannotation. It’s for direct output of a string, not for implicit conversion of an object.