English 中文(简体)
春季主计长无法返回 JSON
原标题:Spring Controller unable to return JSON

我有一个春季控制器, 使用多种方法, 每个方法都根据信头返回 XML 数据或 JSON 数据。 所有方法都成功返回数据, 只有一种方法“ 强” 在返回 JSON 数据 < / 强” 中存在问题。 我在日志中看到的只是“ 500 内部服务器错误 ” 。

我的方法是这样想的:

@RequestMapping (value="/test", method=RequestMethod.GET, headers ={"Accept=text/xml, application/json"})
public @ResponseBody MyObject getMyObject() throws FileNotFoundException, JAXBException {

    return getMyService().getMyObject();
}   

Eclipse 控制台没有显示任何错误, 仅显示“ 500 内部服务器错误” < 坚固 > / 坚固 >, 如果我调试的话, 然后获取 MyServicice () 。 get MyObject () 有正确的数据 。 因此, 500 错误的原因是什么? 为什么它适合 XML 请求, 却不适合 JSON? 谢谢!

问题回答

问题是我没有为MyObject的 几个私人变数提供公共选手。

很明显,当json序列化失败时,这个问题就正在发生(另见杰克逊上的Internal服务器错误@ResponseBody )。虽然我仍不完全清楚,为什么我们不能在春天之前接受例外处理,但这个简短的答案对我来说非常实用:





相关问题
Tomcat´s server.xml dynamic configuration

My web application uses the same database configuration as the application XYZ. I have a resource declaration for a context in server.xml, so I have a duplicated configuration (once for web ...

session transfer issue from Tomcat to ASP.Net

I am using Tomcat to host JSP and using IIS 7.0 to host aspx (C# + .Net 3.5 + VSTS 2008), and I have some session transfer issue from JSP page to ASPX page. JSP page is in one domain and all other ...

JSP exception - class not found (tomcat)

I m setting up an existing application on a new Tomcat 5.5 server connecting to a Postgres database (running on Debian Lenny). When I access it I get a series of stack traces with the following root ...