fastjson 属性大写问题

前端之家收集整理的这篇文章主要介绍了fastjson 属性大写问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

问题:

fastjson 的属性默认是首字母小写的驼峰式分隔, 所以如果首字母是大写的话生成的json 串 有大写的也有小写的(小写是不要的)

{"BPM":120,"bPM":120,"x":9}

解决

在其get 方法前声明下
@JSONField(name = “BPM”) 相当于重命名

{"BPM":120,"x":9}

代码

public class TargetPoint implements Serializable{

    public int x;


    public int BPM;


    public TargetPoint() {
    }




    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    @JSONField(name = "BPM")
    public int getBPM() {
        return BPM;
    }

    public void setBPM(int BPM) {
        this.BPM = BPM;
    }


}

猜你在找的Json相关文章