【发布时间】:2015-08-09 17:52:59
【问题描述】:
这是我的对象
public class ServiceGroup {
private String ParticipantIdentifierScheme;
private String ParticipantIdentifierValue;
public void setParticipantIdentifierScheme(String ParticipantIdentifierScheme) {
this.ParticipantIdentifierScheme = ParticipantIdentifierScheme;
}
public String getParticipantIdentifierScheme() {
return ParticipantIdentifierScheme;
}
public void setParticipantIdentifierValue(String ParticipantIdentifierValue) {
this.ParticipantIdentifierValue = ParticipantIdentifierValue;
}
public String getParticipantIdentifierValue() {
return ParticipantIdentifierValue;
}
这样处理请求
@Path("/participants")
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addUserToSMP(@HeaderParam("authorization") String authString, ServiceGroup sg) {
return Response.ok().entity(sg).build();
}
我已经放了那个小响应,以便查看到底解析了什么。
我的输入应该是这样的
{
"ParticipantIdentifierScheme": "scheme",
"ParticipantIdentifierValue": "value"
}
但是输出如下
{
"participantIdentifierScheme": null,
"participantIdentifierValue": null
}
我真正想要的是以某种方式检查输入是否格式正确,并将它们保存在 ServiceGroup 对象中以供进一步使用
更新
将变量设置为公共返回以下内容
{
"ParticipantIdentifierScheme": "scheme",
"participantIdentifierScheme": "scheme",
"ParticipantIdentifierValue": "value",
"participantIdentifierValue": "value",
}
更新 2
@XmlRootElement
public class ServiceGroup {
@XmlElement(name = "ParticipantIdentifierScheme")
private String ParticipantIdentifierScheme;
@XmlElement(name = "ParticipantIdentifierValue")
private String ParticipantIdentifierValue;
我得到了
{
"ParticipantIdentifierScheme": "scheme",
"participantIdentifierScheme": "scheme",
"ParticipantIdentifierValue": "value",
"participantIdentifierValue": "value"
}
【问题讨论】:
-
以某种方式注释
ServiceGroup sg(可能是@RequestBody)。为类ServiceGroup和字段@XmlElement(name = "ParticipantIdentifierScheme")添加注释@XmlRootElement。 -
@glw 请检查我的更新
-
只是为了测试将
ParticipantIdentifierScheme更改为participantIdentifierScheme