对象转json字符串,属性首字母大写自动变为小写

RegReply r = new RegReply();
            Data d = new Data();
            d.setDateTimestamp(date);
            r.setMessageType("InfoReply");
            r.setDeviceNo(DeviceNo);
            r.setData(d);

            String s = JSON.toJSONString(r);

引入依赖


            com.alibaba
            fastjson
            1.2.56
        

 

实体类上打上注解@JSONField

package com.xw.elevator.platform.mqtt;

import com.alibaba.fastjson.annotation.JSONField;

public class RegReply {

	@JSONField(name="MessageType")
	private String MessageType;

	@JSONField(name="DeviceNo")
	private String DeviceNo;

	@JSONField(name="Data")
	private Data Data;

	public String getMessageType() {
		return MessageType;
	}

	public void setMessageType(String messageType) {
		MessageType = messageType;
	}

	public String getDeviceNo() {
		return DeviceNo;
	}

	public void setDeviceNo(String deviceNo) {
		DeviceNo = deviceNo;
	}

	public Data getData() {
		return Data;
	}

	public void setData(Data data) {
		Data = data;
	}

	@Override
	public String toString() {
		return "RegReply [MessageType=" + MessageType + ", DeviceNo=" + DeviceNo + ", Data=" + Data + "]";
	}

}

 

你可能感兴趣的:(对象转json字符串,属性首字母大写自动变为小写)