【发布时间】:2015-04-06 15:00:06
【问题描述】:
我已经成功地为简单的 WebService 调用(查询参数和简单对象)实现了 Jersey,但是当我尝试 sync 存储或 save 记录时,泽西不理解作者的 rootProperty。它不知道从哪里开始,也无法Consume ExtJS 正在发送的 json 记录。不幸的是,当您将数据转换为 JSON 时,根据 ExtJS,rootProperty 是强制性的,所以我不能没有它。我显然可以使用 Consumes(MediaType.TEXT_PLAIN) 并自己转换对象,但我正在尝试利用 Jersey 的自动对象编组等。
.sync 存储数据或.save 记录的一般做法是什么?
编辑:我认为问题不在于我的对象的 JSON。我店的代理配置如下:
proxy: {
type: 'ajax',
url: 'ext/AnnouncementHelper/myFunction',
headers: {'Content-Type': 'application/json;charset=utf-8'},
reader: {
type: 'json',
rootProperty: 'data',
messageProperty: 'processMessage'
},
writer: {
type: 'json',
rootProperty: 'data',
encode: true,
writeAllFields: true
}
这样做是使用以下参数创建一个 POST 请求:
data={id: 1, description: 'status 1'}
我的模型配置如下:
public class AnnouncementStatus {
private int id;
private String description;
@JsonCreator
public AnnouncementStatus() {
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
我的函数声明是:
@POST
@Path("myFunction")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response myFunction(AnnouncementStatus status)
这在 java 中给了我以下错误:
org.codehaus.jackson.JsonParseException: Unexpected character ('d' (code 100)): 需要一个有效值(数字、字符串、数组、对象、'true'、'false' 或 'null')
我猜杰克逊不喜欢我的对象以data= 开头,但我无法避免这种情况,因为在使用存储和记录时必须具有根属性。
【问题讨论】:
标签: java web-services rest extjs jersey