fastjson2 转换别名 null变空字符串

引入pom

    <dependency>
        <groupId>com.alibaba.fastjson2groupId>
        <artifactId>fastjson2artifactId>
        <version>2.0.45version>
    dependency>

实体类别名

import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Data;

import java.util.List;

@Data
public class BDto {

    @JSONField(name="aa_AA")
    private String aa;
    @JSONField(name="BB_bb")
    private String bb;
    @JSONField(name="list_ll")
    private List<String> ll;

    private Integer ii;

}

json转换

BDto dto = new BDto();
dto.setAa("AAAAAAA");
dto.setBb("111111111");
System.out.println(JSON.toJSONString(dto, JSONWriter.Feature.NullAsDefaultValue));

结果

{"BB_bb":"111111111","aa_AA":"AAAAAAA","ii":0,"list_ll":[]}

你可能感兴趣的:(java)