zoukankan      html  css  js  c++  java
  • 解决PC接口Response接口不规范问题 JsonProperty

    解决PC接口Response接口不规范问题

    在对接平台接口或其他第三方接口的时候,有没有遇到过,Response里面的字段名不规范,并不符合你的想象,和你定义的业务model字段名不一致!不知道你有没有,反正我有!
    解决这个问题的福音就是:@JsonProperty annotation

    Demo as below:


    import com.fasterxml.jackson.annotation.JsonProperty;

    public class JsonPropertyDemoModel {
    /**
    * 每条数据的唯一标识
    * fromat:W5JTkJ2l6E4
    */
    @JsonProperty(value = "abcd")
    private String dataId;

    public String getDataId() {
    return dataId;
    }

    public void setDataId(String dataId) {
    this.dataId = dataId;
    }

    @Override
    public String toString() {
    return "JsonPropertyDemoModel{" +
    "dataId='" + dataId + '\'' +
    '}';
    }
    }

    import com.fasterxml.jackson.databind.ObjectMapper;
    import junit.framework.TestCase;

    /**
    * Created by TonyZeng on 2017/5/23.
    */
    public class FpoPushDataTest extends TestCase {
    public void testGetPulse() throws Exception {
    String json = "{\"abcd\":\"WLVgkMQpG0U\"}";
    JsonPropertyDemoModel bean = new ObjectMapper().readValue(json.getBytes(), JsonPropertyDemoModel.class);
    System.out.println(bean.toString());
    }
    }

    Result of unit test







  • 相关阅读:
    杜教筛刷题总结
    后缀自动机刷题总结
    回文自动机刷题总结
    后缀数组刷题总结
    LCT刷题总结
    省选模拟一题解
    FFT/NTT中档题总结
    二项式反演总结
    JS只能输入数字,数字和字母等的正则表达式
    jquery 条件搜索某个标签下的子标签
  • 原文地址:https://www.cnblogs.com/tonyzeng/p/6895517.html
Copyright © 2011-2022 走看看