I\'m using spring 3.0.0.
I have an endpoint that returns an object that I want to be serialized to JSON. When the request comes in with Accept: application/json, it
I just ran into this same issue. I'm not sure if its more elegant but what I've chosen to do is to just return a string, and convert the object to Json myself. I decided to use Gson for the JSON library.
@Controller
public class NewAbstractController {
@RequestMapping(value = "/simple", method = RequestMethod.GET)
public @ResponseBody String SayHello()
{
Foo foo = new Foo();
foo.Name = "Chris";
foo.age = 30;
Gson gson = new Gson();
return gson.toJson(foo);
}
public class Foo implements Serializable
{
public String Name;
public Integer age;
}
}