为什么我们在 web.xml 中使用它
Why do we use this in web.xml
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
我从 web.xml 中删除了上面的内容,我遇到了一些错误。谁能解释一下 POJOMapping 功能的用途。
如果您想使用 JAX-RS 内置支持将普通的旧 java 对象转换为 JSON 字符串,那么您应该启用它。
参考资源中的以下代码段 class
//<b>com.sun.jersey.api.json.POJOMappingFeature = true</b>
@GET
@Produces(MediaType.APPLICATION_JSON)
public Data getAllData() {
Data data = myService.getAllData();
return data;
}
//JAX-RS takes care of converting Data object into JSON string.
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
我从 web.xml 中删除了上面的内容,我遇到了一些错误。谁能解释一下 POJOMapping 功能的用途。
如果您想使用 JAX-RS 内置支持将普通的旧 java 对象转换为 JSON 字符串,那么您应该启用它。
参考资源中的以下代码段 class
//<b>com.sun.jersey.api.json.POJOMappingFeature = true</b>
@GET
@Produces(MediaType.APPLICATION_JSON)
public Data getAllData() {
Data data = myService.getAllData();
return data;
}
//JAX-RS takes care of converting Data object into JSON string.