是否有用于课程的Jackson json注释?

问题描述 投票:0回答:1

我有带有方法的控制器类:

@RequestMapping(value = "/createchild", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void createChild(@RequestBody Child child) {
    childService.createChild(child);
}

而且当我使用此json时,它是有效的:

{
    "childfullname":"Lok Maen",
    "password": "jfsddsf1",
    "phonenumber": "+79695426314"
}

但是如果我要发布这样的内容:

    {
    "another parameter": "123",
    "child": {
        "childfullname":"Lok Maen",
        "password": "jfsddsf1",
        "phonenumber": "+79155426314"
    }
}

它不起作用。

子类:

@Entity
@Table(name = "child", schema = "cheer")
public class Child {

    @Id
    @Column(name = "childid")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long childId;

    @JsonProperty("childfullname")
    @Column(name = "childfullname")
    private String childFullName;

    @JsonProperty("password")
    @Column(name = "password")
    private String password;
// another code
}

我如何修改代码以在JSON正文中发布另一个参数?

java jackson
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.