[英]Dropwizard reading request JSON
I'm sending a very simple POST request with a JSON body of just "id":"string". 我正在发送一个非常简单的POST请求,其JSON主体仅为“ id”:“ string”。 I get the following in response when I send my post: 发送帖子时得到以下回复:
{
"id": "robert"
}
- -
{
"code": 400,
"message": "Unable to process JSON"
}
- -
@Path("/myapp/user")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class UserHandler {
@POST
public void doPost(Entity e) {
System.out.println(e.id);
}
public class Entity {
@JsonProperty String id;
}
}
I was missing the @JsonProperty identifier... this fixed it: 我错过了@JsonProperty标识符...这解决了它:
public class Entity {
@JsonProperty("id") String id;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.