json字符串中的key是下划线例如:​​foot_dist​​​,而实际实体类中的属性是​​footDist​​​,添加 ​​@JSONField(name = "foot_dist")​​即可

package com.gblfy;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Segments {
@JSONField(name = "line_name")
private String lineName;
@JSONField(name = "foot_dist")
private String footDist;
@JSONField(name = "stat_xys")
private String statXys;
@JSONField(name = "stats")
private String stats;
@JSONField(name = "end_stat")
private String endStat;
@JSONField(name = "line_xys")
private String lineXys;
@JSONField(name = "line_dist")
private String lineDist;
@JSONField(name = "start_stat")
private String startStat;
}
(String[] args) {
Segments build = new Segments().builder()
.footDist("123")
.startStat("456")
.stats("2").build();
System.out.println("sss"+JSON.toJSONString(build));

}

fastjson 序列化时指定json的key值_1024程序员节