在调用rest web服务时,我找不到media type = application / json的MessageBodyWriter。
休息网络服务类: -
@Path("/DBCall")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class AdDAO {
@GET
@Path("/retrieveAds")
@Produces("application/json")
public Response retrieveAds(){
DAOOTPAuthentication dao = new DAOOTPAuthentication();
List<AdBean> AdBeans = dao.getSearchResult("Accommodation", "All Item Types", "All Sub Item Types", "Available", null);
GenericEntity<List<AdBean>> list = new GenericEntity<List<AdBean>>(AdBeans) {};
return Response.ok(list).build();
}
}
Bean类: -
@XmlRootElement(name="adBean")
public class AdBean implements Comparable<AdBean> {
public AdBean() {
super();
}
@XmlElement
private String firstName;
@XmlElement
private String lastName;
@XmlElement
private String emailId;
@XmlElement
private String id;
}
HTML文件: -
<script type="text/javascript">
function valid(){
alert("in jax");
var json;
$.ajax({
type: 'GET',
url: 'softmart/DBCall/retrieveAds',
data: json,
dataType: 'JSON',
success: function (json) {
alert('test');
return true;
},
error: alert('fail')
});
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="jquery-1.12.1.min.js"> </script>
</head>
<body>
<a onclick="valid();"> sClick</a> <br/>
<a href="softmart/DBCall/retrieveAds"> Hello</a>
</body>
</html>
我已经包括了所有的球衣,但我仍然无法运行这个程序。我还包括杰克逊jar但无法运行此代码。我正在使用eclipse进行项目创建和部署。