jackson驼峰注解_fastJson、Jackson对象转json串不使⽤驼峰
⽅法和j。。。
fastJson、Jackson对象转json串不使⽤驼峰⽅法
fastJson可以使⽤JSONField注解,jackson可以使⽤JsonProperty注解,两者结合起来,就可以同时⽀持了
代码⽰例:
package cn.weltman.dp.integrationmon.sp;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationConfig;
import lombok.Data;
import java.io.Serializable;
public class OrderRspTest implements Serializable {
@JSONField(name = "MASTER_ORDER_NO")
private String MASTER_ORDER_NO;
@JSONField(name = "SUB_ORDER_NO")
private String SUB_ORDER_NO;
@JSONField(name = "SUB_ORDER_NO1")
private String SUB_ORDER_NO1;
@JsonProperty("MASTER_ORDER_NO")
public String getMASTER_ORDER_NO() {
return MASTER_ORDER_NO;
}
@JsonProperty("MASTER_ORDER_NO")
public void setMASTER_ORDER_NO(String MASTER_ORDER_NO) {
this.MASTER_ORDER_NO = MASTER_ORDER_NO;
}
@JsonProperty("SUB_ORDER_NO")
public String getSUB_ORDER_NO() {
return SUB_ORDER_NO;
}
@JsonProperty("SUB_ORDER_NO")
public void setSUB_ORDER_NO(String SUB_ORDER_NO) {
this.SUB_ORDER_NO = SUB_ORDER_NO;
}
@JsonProperty("SUB_ORDER_NO1")
public String getSUB_ORDER_NO1() {fastjson常用方法
return SUB_ORDER_NO1;
}
@JsonProperty("SUB_ORDER_NO1")
public void setSUB_ORDER_NO1(String SUB_ORDER_NO1) {
this.SUB_ORDER_NO1 = SUB_ORDER_NO1;
}
public static void main(String[] args) throws JsonProcessingException { MESRspTest mes=new MESRspTest();
mes.setMASTER_ORDER_NO("a");
mes.setSUB_ORDER_NO("b");
mes.setSUB_ORDER_NO1("c");
ObjectMapper mapper = new ObjectMapper();
// figure(SerializationConfig.Feature.INDENT_OUTPUT, Boolean.TRUE); String json = mapper.writeValueAsString(mes);
System.out.println(json);
JSONString(mes);
System.out.println(json);
}
}
json转对象
jackson 只需要在对象的对应属性上加上JsonProperty注解就可以接收到数据,
@JsonProperty("gJAVA")
private String buzei;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。