java Restlet无法处理json
这是我的简单restlet代码:
public class MailServerResource extends ServerResource {
@Get("json")
public String getMail() {
return this.getRequest().getEntityAsText();
}
@Post("json")
public String sendMail() {
return this.getRequest().getEntityAsText();
}
}
现在,当我访问此资源并传递此字符串时:
{"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]}
它抛出:
The server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method
# 1 楼答案
你能试试这个语法吗
带注释的方法可以包含一个表示请求实体(如果有)的参数
注意:顺便说一句,Get请求没有有效负载。本说明没有任何含义: