对接第三方接口要求加密数据按字段名的字母排序
@Data
public class Data6201 {
private String payAuthNo;
private String uldLatlnt;
private String psnNo;
}
转TreeMap后序列化成json字符串,输出到控制台
ObjectMapper objectMapper = new ObjectMapper();
Data6201 data6201 = new Data6201();
TreeMap<String, Object> treeMap = objectMapper.convertValue(data6201, TreeMap.class);
log.info("{}", objectMapper.writeValueAsString(treeMap));
输出格式如下:
{
"payAuthNo": null,
"psnNo": null,
"uldLatlnt": null
}