@JsonProperty not working for Content-Type : application/x-www-form-urlencoded

后端 未结 2 608
温柔的废话
温柔的废话 2021-01-19 14:55

The REST API takes input content type : application/x-www-form-urlencoded, when it is mapped to a Java Object, like

 public class MyRequest {

    @JsonPrope         


        
2条回答
  •  误落风尘
    2021-01-19 15:51

    I think that the very simple solution, is to have a setter related to the variables with "_".

    public class MyRequest {
    
        @JsonProperty("my_name")
        private String myName;
    
        @JsonProperty("my_phone")
        private String myPhone;
    
        //Getters and Setters of myName and myPhone.
    
        //Setters for application/x-www-form-urlencoded
        public void setMy_name(String name) {
            setMyName(name);
        }
        ......
    }
    

    There are more solutions. See the link.

提交回复
热议问题