我的问题:
我使用restkit 0.20在我的iphone应用程序中构建了一个rest客户端。 我的RESTService是用jax-rs构建的,包括jackson。
有一个名为“Customer”的类,我在其中保存客户数据。
@XmlRootElement
public class Customer extends BaseEntity {
private int customer_id;
private String appell;
private String firstname;
private String lastname;
private Date birthday;
private String street;
private String streetnr;
private String zipcode;
private String place;
public int getCustomer_id() {
return customer_id;
}
public void setCustomer_id(int customer_id) {
this.customer_id = customer_id;
}
public String getAppell() {
return appell;
}
public void setAppell(String appell) {
this.appell = appell;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getStreetnr() {
return streetnr;
}
public void setStreetnr(String streetnr) {
this.streetnr = streetnr;
}
public String getZipcode() {
return zipcode;
}
public void setZipcode(String zipcode) {
this.zipcode = zipcode;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
我该怎么办?为什么RestKit中始终记录此错误:
Expected status code in (200-299), got 400" UserInfo=0x956e2f0 {NSLocalizedRecoverySuggestion=Unrecognized field "customer" (Class customer.model.Customer), not marked as ignorable
我没有名为customer的字段。
这是我的POST方法:
@POST
@Path("/insert")
@Consumes(MediaType.APPLICATION_JSON)
public Response insertCustomer(Customer customer) {
String result = "Customer inserted " + customer.getLastname();
customer.createEntity();
return Response.status(201).type(MediaType.APPLICATION_JSON).entity(result).build();
}
这是在我的ios应用程序中调用@GET方法时生成的JSON对象(Jackson)的示例。
{
"appell": "Frau",
"birthday": "1991-10-01T00:00:00+01:00",
"customer_id": "3",
"firstname": "Max",
"lastname": "Mustermann",
"place": "München",
"street": "Einsteinweg",
"streetnr": "19",
"zipcode": "81858"
}
这是JSON对象的一个示例,当我的ios应用程序调用show @POST方法时:
{"customer":{"streetnr":"19",
"zipcode":"81829",
"customer_id":0,
"place":"München",
"appell":"Herr",
"firstname":"Heinrich",
"birthday":"1991-10-01T00:00:00+01:00",
"lastname":"Maier",
"street":"Lehrer-Wirth-Str.19"}}
我是一个使用restkit和jax-rs的绝对新手。
我刚刚添加了一个@GET方法来请求xml格式。 在这里你可以看到它:
@GET
@Path("/listallcustomers")
@Produces(MediaType.APPLICATION_XML)
public ArrayList<Customer> showAllCustomers() {
ArrayList<Customer> list = DBAccess.getInstance().getAllCustomers();
return list;
}
这就是结果:
<customers>
<customer>
<appell>Frau</appell>
<birthday>1991-10-01T00:00:00+01:00</birthday>
<customer_id>3</customer_id>
<firstname>Max</firstname>
<lastname>MUstermann</lastname>
<place>München</place>
<street>Einsteinstr.</street>
<streetnr>19</streetnr>
<zipcode>82838</zipcode>
</customer>
...
我创建JSON对象的@GET方法如下:
@GET
@Path("/listall")
@Produces(MediaType.APPLICATION_JSON)
public ArrayList<Customer> showAllJsonCustomers() {
ArrayList<Customer> list = DBAccess.getInstance().getAllCustomers();
return list;
}
这是它创建的JSON对象的一个示例:
{
"lastname": "Müller",
"customer_id": 6,
"appell": "Herr",
"firstname": "pupsi",
"birthday": "1986-10-16",
"street": "Lehrer-Wirth-Str",
"streetnr": "19",
"zipcode": "81829",
"place": "München"
},
...