当我将json作为我的模型类时,我的服务出错了, 如果我的模型字段有公共然后没有问题一切正常,但如果私有和getter和setter然后有问题不能理解我的模型为json。
这是我的服务类:
library(rvest)
library(plyr)
read_html(file) %>%
html_nodes(xpath = "//input[contains(@name,'_ctl0:PlaceHolderContenido')]") %>%
html_attrs() %>%
sapply(function(x) as.list(x) %>% as.data.frame) %>%
do.call(rbind.fill, .)
模特:
@POST
@Path("/test")
@Produces("application/json")
@Consumes("application/json")
public LoginResponse loginVTS(Login login) throws Exception {
......
}
pom.xml依赖:
@JsonIgnoreProperties(ignoreUnknown = true)
public class Login {
private String UserId;
private String Password;
public Login() {}
public String getUserId() {
return UserId;
}
public void setUserId(String userdId) {
UserId = userdId;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
@Override
public String toString() {
return "Login{" +
"UserId='" + UserId + '\'' +
", Password='" + Password + '\'' +
'}';
}
}
如果我使用私有字段和getter,那么当客户端调用我的服务时,setter会抛出此错误:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.4.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
任何人都可以帮我解决这个问题。