1、枚举添加注解
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
2、转换
ObjectMapper mapper = new ObjectMapper();
System.out.println(mapper.writeValueAsString(Bank.values()));
3、输出
4、转换为指定Object
@JsonProperty("value") // 设置输出后的名称
private Integer bankCode;
@JsonProperty("content")
private String bankName;
5、转换输出
List<BankListDTO> list = mapper.readValue(json,new TypeReference<List<BankListDTO>>(){});
System.out.println(list);