gpt4 book ai didi

java - Dropwizard 读取请求 JSON

转载 作者:行者123 更新时间:2023-12-02 11:20:25 25 4
gpt4 key购买 nike

我正在发送一个非常简单的 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;
}
}

最佳答案

我缺少 @JsonProperty 标识符...这修复了它:

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

关于java - Dropwizard 读取请求 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49961600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com