@JsonValue

@JsonValue

序列化时,调用方法序列化
当注释掉 @JsonValue时


JsonModel jsonModel = new JsonModel();
jsonModel.setName("maqingbin");
jsonModel.setLoginCode("loginCode");

String targetVal = objectMapper.writeValueAsString(jsonModel);
System.out.println(targetVal);
{"name":"maqingbin","loginCode":"loginCode"}

--------------------------------------
如果将@JsonValue注释去掉放开后  打印的结果为 "maqingbin"

猜你喜欢

转载自blog.csdn.net/maqingbin8888/article/details/82927636