I defined an endpoint with the following methods:
我用以下方法定义了一个端点:
@ApiMethod(name = "update", path = "properties/{id}", httpMethod = HttpMethod.PUT)
public void update(@Named("id") Long id, RealEstatePropertyAPI propertyAPI,
User user) {
On the client side I tried several calls but none of them populates the propertyAPI
object on the server side. The instance is created with all fields set to null
except the id
.
在客户端,我尝试了几个调用,但没有一个调用服务器端的propertyAPI对象。创建实例时,除id之外,所有字段都设置为null。
var jsonId = { 'id': '11'};
var x = {"name": "Test","address": { "street": "White House"}};
gapi.client.realestate.update(jsonId, x).execute(function(resp) {
console.log('PropertyEdited');
console.log(resp);
});
Or
要么
var jsonId = { 'id': '11'};
var x = {"name": "Test","address": { "street": "White House"}};
gapi.client.realestate.update(jsonId, {'resource' : x}).execute(function(resp) {
console.log('PropertyEdited');
console.log(resp);
});
The Java classes:
Java类:
public class RealEstatePropertyAPI {
private Long id;
private String name;
private AddressAPI address;
public RealEstatePropertyAPI() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public AddressAPI getAddress() {
return address;
}
public void setAddress(AddressAPI address) {
this.address = address;
}
}
public class AddressAPI {
private Long id;
private String street;
private String city;
private String state;
private String zip;
private String country;
public AddressAPI() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getZip() {
return zip;
}
public void setZip(String zip) {
this.zip = zip;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
1 个解决方案
#1
0
I'm not actually sure about about this, but you can try to pass all the parameters within a single object, I mean wrap the parameters with brackets { }
, like this:
我真的不确定这个,但是你可以尝试在一个对象中传递所有参数,我的意思是用括号{}包装参数,如下所示:
//var jsonId = { 'id': '11'};
var x = {"name": "Test","address": { "street": "White House"}};
gapi.client.realestate.update({'id': '11', 'resource' : x}).execute(function(resp) {
console.log('PropertyEdited');
console.log(resp);
});
Because in fact in both your requests you're sending 2 objects...
And I think you have to use 'resource'
for the parameters in the POST data as in your second option...
因为事实上在你的两个请求中你都发送了2个对象......我认为你必须在POST数据中使用'resource'作为第二个选项中的参数......
#1
0
I'm not actually sure about about this, but you can try to pass all the parameters within a single object, I mean wrap the parameters with brackets { }
, like this:
我真的不确定这个,但是你可以尝试在一个对象中传递所有参数,我的意思是用括号{}包装参数,如下所示:
//var jsonId = { 'id': '11'};
var x = {"name": "Test","address": { "street": "White House"}};
gapi.client.realestate.update({'id': '11', 'resource' : x}).execute(function(resp) {
console.log('PropertyEdited');
console.log(resp);
});
Because in fact in both your requests you're sending 2 objects...
And I think you have to use 'resource'
for the parameters in the POST data as in your second option...
因为事实上在你的两个请求中你都发送了2个对象......我认为你必须在POST数据中使用'resource'作为第二个选项中的参数......