Question

following is my pojo :

package anto.com.poc;
public class VerifyPaymentRO {

private String mihpayid;
private String request_id;
private String bank_ref_num;
private String amt;
private String disc;
private String mode;
private String PG_TYPE;
private String card_no;
private String name_on_card;
private String udf2;
private String addedon;
private String status;
private String unmappedstatus;
private String Merchant_UTR;
private String Settled_At;

public String getMihpayid() {
    return mihpayid;
}
public void setMihpayid(String mihpayid) {
    this.mihpayid = mihpayid;
}
public String getRequest_id() {
    return request_id;
}
public void setRequest_id(String request_id) {
    this.request_id = request_id;
}
public String getBank_ref_num() {
    return bank_ref_num;
}
public void setBank_ref_num(String bank_ref_num) {
    this.bank_ref_num = bank_ref_num;
}
public String getAmt() {
    return amt;
}
public void setAmt(String amt) {
    this.amt = amt;
}
public String getDisc() {
    return disc;
}
public void setDisc(String disc) {
    this.disc = disc;
}
public String getMode() {
    return mode;
}
public void setMode(String mode) {
    this.mode = mode;
}
public String getPG_TYPE() {
    return PG_TYPE;
}
public void setPG_TYPE(String pG_TYPE) {
    PG_TYPE = pG_TYPE;
}
public String getCard_no() {
    return card_no;
}
public void setCard_no(String card_no) {
    this.card_no = card_no;
}
public String getName_on_card() {
    return name_on_card;
}
public void setName_on_card(String name_on_card) {
    this.name_on_card = name_on_card;
}
public String getUdf2() {
    return udf2;
}
public void setUdf2(String udf2) {
    this.udf2 = udf2;
}
public String getAddedon() {
    return addedon;
}
public void setAddedon(String addedon) {
    this.addedon = addedon;
}
public String getStatus() {
    return status;
}
public void setStatus(String status) {
    this.status = status;
}
public String getUnmappedstatus() {
    return unmappedstatus;
}
public void setUnmappedstatus(String unmappedstatus) {
    this.unmappedstatus = unmappedstatus;
}
public String getMerchant_UTR() {
    return Merchant_UTR;
}
public void setMerchant_UTR(String merchant_UTR) {
    Merchant_UTR = merchant_UTR;
}
public String getSettled_At() {
    return Settled_At;
}
public void setSettled_At(String settled_At) {
    Settled_At = settled_At;
}


}

and I am trying to set values at run time like the following :

static public VerifyPaymentRO convertToVerifyPaymentPOJO(String verifyPaymentInfo) {
        VerifyPaymentRO verifyPaymentRO = new VerifyPaymentRO();
        String[] verifyPaymentComma=null;
        String[] verifyPayment=null;
        String value="";

        verifyPaymentComma = verifyPaymentInfo.trim().split(",");
        for (String verifyPaymentCommaSeparated : verifyPaymentComma) {
            verifyPayment = verifyPaymentCommaSeparated.trim().split("=");
            if(verifyPayment.length==2){
                value=verifyPayment[1];
            }else{
                value="";
            }

             try {

                 if(verifyPayment[0].trim().equals("mihpayid"))
                     PropertyUtils.setProperty(verifyPaymentRO, "mihpayid", value.trim());
                 if(verifyPayment[0].trim().equals("request_id"))
                     PropertyUtils.setProperty(verifyPaymentRO, "request_id", value.trim());
                 if(verifyPayment[0].trim().equals("bank_ref_num"))
                     PropertyUtils.setProperty(verifyPaymentRO, "bank_ref_num", value.trim());
                 if(verifyPayment[0].trim().equals("amt"))
                     PropertyUtils.setProperty(verifyPaymentRO, "amt", value.trim());
                 if(verifyPayment[0].trim().equals("disc"))
                     PropertyUtils.setProperty(verifyPaymentRO, "disc", value.trim());
                 if(verifyPayment[0].trim().equals("mode"))
                     PropertyUtils.setProperty(verifyPaymentRO, "mode", value.trim());
                 if(verifyPayment[0].trim().equals("PG_TYPE"))
                     PropertyUtils.setProperty(verifyPaymentRO, "PG_TYPE", value.trim());
                 if(verifyPayment[0].trim().equals("card_no"))
                     PropertyUtils.setProperty(verifyPaymentRO, "card_no", value.trim());
                 if(verifyPayment[0].trim().equals("name_on_card"))
                     PropertyUtils.setProperty(verifyPaymentRO, "name_on_card", value.trim());
                 if(verifyPayment[0].trim().equals("udf2"))
                     PropertyUtils.setProperty(verifyPaymentRO, "udf2", value.trim());
                 if(verifyPayment[0].trim().equals("addedon"))
                     PropertyUtils.setProperty(verifyPaymentRO, "addedon", value.trim());
                 if(verifyPayment[0].trim().equals("status"))
                     PropertyUtils.setProperty(verifyPaymentRO, "status", value.trim());
                 if(verifyPayment[0].trim().equals("unmappedstatus"))
                     PropertyUtils.setProperty(verifyPaymentRO, "unmappedstatus", value.trim());
                 if(verifyPayment[0].trim().equals("unmappedstatus"))
                     PropertyUtils.setProperty(verifyPaymentRO, "unmappedstatus", value.trim());
                 if(verifyPayment[0].trim().equals("Merchant_UTR"))
                     PropertyUtils.setProperty(verifyPaymentRO, "Merchant_UTR", value.trim());
                 if(verifyPayment[0].trim().equals("Settled_At"))
                     PropertyUtils.setProperty(verifyPaymentRO, "Settled_At", value.trim());

                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                }



        }

        return verifyPaymentRO;
    }

everything works fine but for the last two properties I get the following exception :

1. java.lang.NoSuchMethodException: Unknown property 'Merchant_UTR' on class 'class anto.com.poc.VerifyPaymentRO'

2. java.lang.NoSuchMethodException: Unknown property 'Settled_At' on class 'class anto.com.poc.VerifyPaymentRO'

but these two fields are available and I get the above exception only for the above two fields and rest are working fine.

so what could cause the issue?

thanks

Was it helpful?

Solution 2

The correct property names would start lowecase: merchant_UTR and settled_At.

Btw, the redundancy in your code hurts and also makes your code very error-prone (copy-paste errors). Why not rewrite it to something like this:

List<String> validProperties = Arrays.asList("mihpayid", "request_id", "bank_ref_num", ...);
String property = verifyPayment[0].trim();
if (validProperties.contains(property)) {
    try {
        PropertyUtils.setProperty(verifyPaymentRO, property, value.trim());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

OTHER TIPS

use merchant_UTR and settled_At In the last two methods

if(verifyPayment[0].trim().equals("Merchant_UTR"))
                     PropertyUtils.setProperty(verifyPaymentRO, "merchant_UTR", value.trim());
                 if(verifyPayment[0].trim().equals("Settled_At"))
                     PropertyUtils.setProperty(verifyPaymentRO, "settled_At", value.trim());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top