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;
    }


}

猜你喜欢

转载自blog.csdn.net/lckj686/article/details/72841577