【发布时间】:2018-02-14 06:57:44
【问题描述】:
我正在尝试使用 @RequestBody Instance instance 将以下 Json 导入 POJOS
{
"service_id": "service-id-here",
"plan_id": "plan-id-here",
"context": {
"platform": "cloudfoundry",
"some_field": "some-contextual-data"
},
"organization_guid": "org-guid-here",
"space_guid": "space-guid-here",
"parameters": {
"agent_name": 1,
"url": "foo",
"credential": "asdasd",
"ia_url": "asdasd"
}
}
以下是我的 POJO
实例
public class Instance {
@JsonProperty(value = "service_id")
String serviceId;
@JsonProperty(value = "plan_id")
String planId;
//TODO : Replace with Context class when the spec defines things clearly
@JsonProperty(value = "context")
Object context;
@JsonProperty(value = "organization_guid")
String organizationGuid;
@JsonProperty(value = "space_guid")
String spaceGuid;
@JsonProperty(value = "parameters")
Parameters parameters;
}
参数
public class Parameters {
@JsonProperty(value = "agent_name")
String agentName;
@JsonProperty(value = "url")
String url;
@JsonProperty(value = "credential")
String credential;
@JsonProperty(value = "ia_url")
String iaUrl;
}
我在任何地方都使用@JsonProperty。有没有办法将下划线分隔的json键放入java的变量命名约定(Camelcase)??
我尝试在我的 POJO 类中使用 @JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class),而不是为每个参数使用 @JsonProperty。我只是在instance 中得到一个空的json {}。我在这里错过了什么?
【问题讨论】:
标签: java json spring-mvc pojo