Lombokとjacksonを用いてシーケンス化する際の爆発的な問題
4431 ワード
エンティティークラスは次のとおりです.
次のようにテストされました.
使用するjacksonバージョン2.9.5
lombokバージョンは1.16.20です
Spring bootプロジェクト
なぜJsonDto 2は1つの属性値を多く出すことができて、これはいったい谁の问题ですか???
原文:https://zhuanlan.zhihu.com/p/37439920
@Data
public class JsonDto {
private String cDay;
private String ceDay;
public JsonDto() {
}
public JsonDto(String cDay, String ceDay) {
this.cDay = cDay;
this.ceDay = ceDay;
}
}
public class JsonDto1 {
private String cDay;
private String ceDay;
public String getcDay() {
return cDay;
}
public void setcDay(String cDay) {
this.cDay = cDay;
}
public String getCeDay() {
return ceDay;
}
public void setCeDay(String ceDay) {
this.ceDay = ceDay;
}
public JsonDto1() {
}
public JsonDto1(String cDay, String ceDay) {
this.cDay = cDay;
this.ceDay = ceDay;
}
}
@Data
public class JsonDto2 {
@JsonProperty
private String cDay;
private String ceDay;
public JsonDto2() {
}
public JsonDto2(String cDay, String ceDay) {
this.cDay = cDay;
this.ceDay = ceDay;
}
}
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* @author Reese
*/
public class JsonDto3 {
@JsonProperty
private String cDay;
private String ceDay;
public String getcDay() {
return cDay;
}
public void setcDay(String cDay) {
this.cDay = cDay;
}
public String getCeDay() {
return ceDay;
}
public void setCeDay(String ceDay) {
this.ceDay = ceDay;
}
public JsonDto3() {
}
public JsonDto3(String cDay, String ceDay) {
this.cDay = cDay;
this.ceDay = ceDay;
}
}
public class JsonDto4 {
private String cDay;
private String ceDay;
public String getCDay() {
return cDay;
}
public void setCDay(String cDay) {
this.cDay = cDay;
}
public String getCeDay() {
return ceDay;
}
public void setCeDay(String ceDay) {
this.ceDay = ceDay;
}
public JsonDto4() {
}
public JsonDto4(String cDay, String ceDay) {
this.cDay = cDay;
this.ceDay = ceDay;
}
}
次のようにテストされました.
@RestController
public class JsonDtoController {
/**
* {"ceDay":null,"cday":null}
* @return
*/
@GetMapping("/jd")
public JsonDto get(){
return new JsonDto();
}
/**
* {"cDay":null,"ceDay":null}
* @return
*/
@GetMapping("/jd1")
public JsonDto1 get1(){
return new JsonDto1();
}
/**
* {"cDay":null,"ceDay":null,"cday":null}
*
* @return
*/
@GetMapping("/jd2")
public JsonDto2 get2(){
return new JsonDto2();
}
/**
* {"cDay":null,"ceDay":null}
* @return
*/
@GetMapping("/jd3")
public JsonDto3 get3(){
return new JsonDto3();
}
/**
* {"ceDay":"BB","cday":"aa"}
* @return
*/
@GetMapping("/jdc")
public JsonDto getc(){
return new JsonDto("aa","BB");
}
/**
* {"ceDay":"BB","cDay":"aa"}
* @return
*/
@GetMapping("/jd1c")
public JsonDto1 get1c(){
return new JsonDto1("aa","BB");
}
/**
* {"cDay":"aa","ceDay":"BB","cday":"aa"}
* @return
*/
@GetMapping("/jd2c")
public JsonDto2 get2c(){
return new JsonDto2("aa","BB");
}
/**
* {"ceDay":"BB","cDay":"aa"}
* @return
*/
@GetMapping("/jd3c")
public JsonDto3 get3c(){
return new JsonDto3("aa","BB");
}
/**
* {"ceDay":"BB","cDay":"aa"}
* @return
*/
@GetMapping("/jd4")
public JsonDto4 get4(){
return new JsonDto4("aa","BB");
}/**
* {"ceDay":"BB","cDay":"aa"}
* @return
*/
@GetMapping("/jd4c")
public JsonDto4 get4c(){
return new JsonDto4("aa","BB");
}
}
使用するjacksonバージョン2.9.5
lombokバージョンは1.16.20です
Spring bootプロジェクト
なぜJsonDto 2は1つの属性値を多く出すことができて、これはいったい谁の问题ですか???
原文:https://zhuanlan.zhihu.com/p/37439920