【问题标题】:Dropwizard reading request JSONDropwizard 读取请求 JSON
【发布时间】:2018-04-22 01:05:27
【问题描述】:

我正在发送一个非常简单的 POST 请求,其 JSON 正文只是“id”:“string”。我在发送帖子时收到以下回复:

{
    "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;
    }
}

【问题讨论】:

    标签: java json jackson jersey dropwizard


    【解决方案1】:

    我错过了@JsonProperty 标识符...这已修复它:

    public class Entity {
        @JsonProperty("id") String id;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      • 2014-09-13
      • 1970-01-01
      • 2015-06-27
      • 2012-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多