我ModelClass我只想在少數情況下忽略來自JSON的字段是否可能?
public class UserPojo{
private String userEmailId;
private String userPassword;
private String userContactNumber;
//setters and getters
}
我想送UserPojo類對象爲JSON,但在一些情況下我想,userPassword爲發送和無的userPassword一些情況下這可能嗎?
在下面的方法中,我想發送沒有userpassword的userPojo對象。 我的春季版本是4.3.1.RELEASE。我有傑克遜庫
@RestController
@RequestMapping("/user")
public class UserController{
@GetMapping(value="/{userId}")
public UserPojo getUser(@PathVariable("userId") String userId){
//code goes here
//finally returning UserPojo Object
return userPojo;
}
}
在下面的方法我想送userPojo對象與密碼
@RestController
@RequestMapping("/admin")
public class AdminController{
@GetMapping(value="/{userId}")
public UserPojo getUser(@PathVariable("userId") String userId){
//code goes here
//finally returning UserPojo Object
return userPojo;
}
}
我希望你有我的觀點
你想在什麼情況下忽略字段? – ThatAwesomeCoder
當然,你試過了嗎?你的json庫應該自動執行,如果你需要更多的需求請解釋 –