我从 RESTful 服务返回了以下 JSON
{
"Status": "Success",
"Success": true,
"Path": "D:\\Work\\Sites\\EKSites\\OnTrek\\privateassets\\0\\155\\156\\ceb3dc64-33ed-4e96-80a2-846120ecd9ee.pdf",
"Timestamp": "2013-03-27T18:35:23.8997358-04:00"
}
我正在尝试将 JSON 反序列化为这个数据类:
package ektron.cms.jdbc.extractors;
@JsonPropertyOrder({ "Status", "Success", "Path", "Timestamp" })
public class AssetDataResponse {
@JsonProperty("Status")
private String Status;
@JsonProperty("Success")
private Boolean Success;
@JsonProperty("Path")
private String Path;
@JsonProperty("Timestamp")
private String Timestamp;
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
@JsonProperty("Status")
public String getStatus() {
return Status;
}
@JsonProperty("Status")
public void setStatus(String Status) {
this.Status = Status;
}
@JsonProperty("Success")
public Boolean getSuccess() {
return Success;
}
@JsonProperty("Success")
public void setSuccess(Boolean Success) {
this.Success = Success;
}
@JsonProperty("Path")
public String getPath() {
return Path;
}
@JsonProperty("Path")
public void setPath(String Path) {
this.Path = Path;
}
@JsonProperty("Timestamp")
public String getTimestamp() {
return Timestamp;
}
@JsonProperty("Timestamp")
public void setTimestamp(String Timestamp) {
this.Timestamp = Timestamp;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperties(String name, Object value) {
this.additionalProperties.put(name, value);
}
}
以下是我的客户端代码:
package ektron.common.network;
//...
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
clientConfig.getClasses().add(JacksonJsonProvider.class);
client = Client.create(clientConfig);
WebResource webResource =
client.resource(
String.format("http://%s:%d/%s","localhost",7605,"asset"));
String return =
webResource
.path("3f7078c4")
.path("ceb3dc64-33ed-4e96-80a2-846120ecd9ee")
.accept(MediaType.APPLICATION_JSON)
.get(String.class); //This piece works and I get my JSON response as
//indicated above
但是,如果我将以上内容更改为:
AssetDataResponse resp =
webResource
.path("3f7078c4")
.path("ceb3dc64-33ed-4e96-80a2-846120ecd9ee")
.accept(MediaType.APPLICATION_JSON)
.get(AssetDataResponse.class);
我收到以下错误:
无法识别的字段“状态”(类 ektron.cms.jdbc.extractors.AssetDataResponse),未标记为可忽略
我需要在 ClientConfig 上进行任何配置以使反序列化正常工作吗?对此的任何帮助将不胜感激。我是 .NET 开发人员,对 Java 很陌生,对 Jersey 框架不太熟悉。我已经检查了一个类似问题的答案,我的案例与那里列出的案例不同。
客户端罐子
- annotations-1.3.9.jar
- asm-3.1.jar
- codemodel-2.4.1.jar
- 杰克逊注释-2.1.2.jar
- 杰克逊核心2.1.3.jar
- 杰克逊核心asl-1.9.11.jar
- jackson-databind-2.1.3.jar
- 杰克逊-jaxrs-1.9.2.jar
- jackson-mapper-asl-1.9.11.jar
- 杰克逊-xc-1.9.2.jar
- jcommander-1.30.jar
- jersey-apache-client-1.17.jar
- jersey-atom-abdera-1.17.jar
- jersey-client-1.17.jar
- jersey-core-1.17.jar
- jersey-guice-1.17.jar
- jersey-json-1.17.jar
- jersey-multipart-1.17.jar
- jersey-server-1.17.jar
- jersey-servlet-1.17.jar
- 抛弃-1.1.jar
- jsr311-api-1.1.1.jar
- 验证-api-1.0.0.GA.jar