Reputation:
When i try to return an error message from my spring mvc controller requestmapping to postman tool , I am also getting an extra a null value.
My RequestMapping:
@RequestMapping(value="/getcompanystatus",method=RequestMethod.GET)
public List<CompanyStatusMaster> getCompanyStatus()
{
List<CompanyStatusMaster> companyStatus=userService.getCompanyStatus();
return companyStatus;
}
@RequestMapping(value="/getstates",method=RequestMethod.GET)
public List<StatesMaster> getstates()
{
List<StatesMaster> statesList=userService.getStates();
return statesList;
}
@RequestMapping(value="/getcompanies", method=RequestMethod.POST)
public CompaniesPresenter getCompanies(@RequestBody UserDetails user)
{
String OrgLoginId=user.getOrgLoginId();
String password=user.getuPassword();
String checkLoginId=null;
String uPassword=null;
String encPassword=null;
String loginId=null;
String checkAuthorized=null;
String checkOrgloginId=userService.getLoginId(OrgLoginId);
if(checkOrgloginId==null){
return new CompaniesPresenter("Incorrect loginId..Please enter valid loginId");
}
List<Object[]> CheckIdPassword=userService.checkLoginId(OrgLoginId);
List<Object[]> results = CheckIdPassword;
for(Object[] obj:results){
checkLoginId=obj[0].toString();
if(null==obj[1]){
uPassword="";
}else{
uPassword=obj[1].toString();
}
loginId=obj[2].toString();
}
checkAuthorized=loginId.substring(0,3);
if (null != password) {
MD5 md5 = new MD5();
encPassword = md5.getPassword(password);
}
if(encPassword.equals(uPassword))
{
if (checkAuthorized.equals("STE"))
{
List<CompanyMaster> companyList=userService.getCompanyList(OrgLoginId);
if(companyList.isEmpty())
{
return new CompaniesPresenter("Sorry..No companies for the user id");
}
else
{
return new CompaniesPresenter("select company from the below list",companyList) ;
}
}
else
{
return new CompaniesPresenter("You are not Authorized");
}
}
else
{
return new CompaniesPresenter("Incorrect Password");
}
}
My CompaniesPresenter class:
public class CompaniesPresenter {
private String status;
private List<CompanyMaster> companyMaster;
public CompaniesPresenter()
{
}
public CompaniesPresenter(String status) {
this.status = status;
}
public CompaniesPresenter(List<CompanyMaster> companyMaster) {
this.companyMaster = companyMaster;
}
public CompaniesPresenter(String status, List<CompanyMaster> companyMaster) {
this.status = status;
this.companyMaster = companyMaster;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public List<CompanyMaster> getCompanyMaster() {
return companyMaster;
}
public void setCompanyMaster(List<CompanyMaster> companyMaster) {
this.companyMaster = companyMaster;
}
}
My postman tool result: { "status": "Sorry..No companies for the user id", "companyMaster": null }
I dont want the "companyMaster": null. I just want the "status": "Sorry..No companies for the user id" .I dont know why i Am getting that. please help me..For all the return values I am getting that.Thank you
Upvotes: 0
Views: 293
Reputation: 69440
Add @JsonInclude(Include.NON_NULL)
to your pojo:
@JsonInclude(Include.NON_NULL)
public class CompaniesPresenter {
private String status;
private List<CompanyMaster> companyMaster;
..}
Upvotes: 4