1
其余API未能与400错误请求与响应下面REST API与javax.xml.bind.JAXBException(400错误的请求)
javax.xml.bind.JAXBException 失败 - 与链接的异常: [org.codehaus.jettison.json.JSONException:一个JSONObject文本必须以 '{' 以字符0]
下面是我的代码,
API资源
@GET
@Path("/getTeams")
@Produces(MediaType.APPLICATION_JSON)
public Response getTeamList(final TeamSearchRequest teamSearchRequest, @Context UriInfo uriInfo) {
//Business
}
请求类
@XmlRootElement(name = "teamSearchRequest")
public class TeamSearchRequest {
private String searchText;
private String searcherTeamId;
public TeamSearchRequest(){}
//setters and getters
}
API URI - http://localhost:8080/letsplay/team/getTeams
API请求体 -
{
"teamSearchRequest": {
"searchText": "Mumbai",
"searcherTeamId": "1"
}
}
注意 - 我已经检查了所有类似的问题在左右。
任何建议是非常感谢。
您是否为您的项目设置了media-moxy依赖项以启用JSON支持?假设你正在使用Jersey .. – Prathap
@Prathap,我使用Spring Rest Integration而不是Jersey,所以media-moxy不适用。 –
您是否使用JSONObject来映射请求值?如果是这样,您可以将'JSONObject'作为方法参数而不是'TeamSearchRequest',然后执行'jsonObject.getJSONObject(“teamSearchRequest”)'来获得所需的值。 – Prathap