Response.java
public class Response{
private String mobileNo;
private String contractId;
private String sim;
private String imei;
public Response(String mobileNo, String contractId){
    this.mobileNo = mobileNo;
    this.contractId = contractId;
}
public Response(String mobileNo, String contractId, String sim,
        String imei, String identificationType) {
    this.mobileNo = mobileNo;
    this.contractId = contractId;
    this.sim = sim;
    this.imei = imei;
    this.identificationType = identificationType;
}
//Getter and Setter
}
MainEx.java
public class MainEx{
   Response  response = null;  
   public Response response(){
     String mobileNo = null;
     String contractId = null;
     String sim = null;
     String imei = null;
     if(something){
        response= new IVRAccountDetailsRs("777","4545"); 
     }
     else{
        response= new IVRAccountDetailsRs("777","4545","sim","imei");
     }
    return response;
   }
}
When if statement call return response as
{ "mobileNo" = "777";
  "contractId" = "4545";
  "sim"= null;
  "imei" = null;
}
But I want to get the response as bellow,
When calling if statement
Need to remove other two values.
{ "mobileNo" = "777";
  "contractId" = "4545";
}
If contractId and mobileNo null then output should be
{ "mobileNo" = null;
  "contractId" = null;
}
When calling else statement
{ "mobileNo" = "777";
  "contractId" = "4545";
  "sim"= "sim";
  "imei" = "imei";
}
if all values null
 { "mobileNo" = null;
      "contractId" = null;
      "sim"= null;
      "imei" =null;
    }
Used Jackson version is 2.4.1
What can I do about this?
 
     
     
     
    