Fastjson转换json字符串key的首字母大写变小写的解决办法

在使用fastjson的时候,一般默认对象转换成的字符串key的首字母是小写的,而json字符串转换成java bean对象的时候,json字符串怎么写的,封装javabean的时候就要怎么写,这样才能成功set值给javabean。如果需要将javabean转换json字符串时key的首字母大写可以使用fastjson 的注解 @JSONField,例如:
 

/**
 * @author chenjianwei
 * @date 2019年11月7日
 */
public class TestModel {
	@JSONField(name="ICCID")
	String ICCID;
	@JSONField(name="IMEI")
	String IMEI;
	@JSONField(name="IP")
	String IP;
	@JSONField(name="MAC")
	String MAC;
	/**
	 * @return the iCCID
	 */
	public String getICCID() {
		return this.ICCID;
	}
	/**
	 * @param iCCID the iCCID to set
	 */
	public void setICCID(String iCCID) {
		this.ICCID = iCCID;
	}
	/**
	 * @return the iMEI
	 */
	public String getIMEI() {
		return this.IMEI;
	}
	/**
	 * @param iMEI the iMEI to set
	 */
	public void setIMEI(String iMEI) {
		this.IMEI = iMEI;
	}
	/**
	 * @return the iP
	 */
	public String getIP() {
		return this.IP;
	}
	/**
	 * @param iP the iP to set
	 */
	public void setIP(String iP) {
		this.IP = iP;
	}
	/**
	 * @return the mAC
	 */
	public String getMAC() {
		return this.MAC;
	}
	/**
	 * @param mAC the mAC to set
	 */
	public void setMAC(String mAC) {
		this.MAC = mAC;
	}
	
}

@Test
	public void fastJsonTest() {
		TestModel aa = new TestModel();
		aa.setICCID("ASDF");
		aa.setIMEI("ASDF");
		aa.setIP("ASDF");
		aa.setMAC("ASDF");
		
		String aaa = JSONObject.toJSONString(aa);
		System.out.println(aaa);
		
	}

{"ICCID":"ASDF","IMEI":"ASDF","IP":"ASDF","MAC":"ASDF"}
 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值