mercredi 28 novembre 2018

Deleting contents from an Object which matches content of ArrayList in Java

Given an Object mergeDiff of Class LeadDetailsSRO as:

LeadDetailsSRO mergeDiff = new LeadDetailsSRO();
public class LeadDetailSRO {
    private List<DocumentSRO>       uploadDocumentList;
    private BusinessOwnerSRO        businessOwnerDetails;
    private List<BusinessOwnerSRO>  businessOwnerDetailList;
    private List<BusinessOwnerSRO>  authorizedSignatoryList;
    private BusinessEntitySRO       businessEntityDetails;
    private LeadInfoSRO             leadInfo;
    private BankDetailSRO           bankDetails;
    private AddressSRO              addressDetails;
    private CFAAgentDetailsSRO      cfaAgent;
    private VerificationAgentSRO    vaAgent;
    private AuditTrailSRO           auditTrail;
    private AdditionalDetailsSRO    additionalDetails;
    private QuestionAnsersSRO       additionalQuestions;
    private List<DocumentSRO>       documents;
    private List<AgentDetailsSRO>   agentDetails;
    private Set<TimelineSRO>        timelineDetail;
    private NOCStatusSRO            nocStatus;
    private Map<String, Integer>    docAcceptanceMap;
    private List<SlabDataSRO>       slabDataList;
    private UserConfiguration       userConfiguration;
}

Given an ArrayList deleteFields which contains the values of fields to be deleted from mergeDiff:

The contents of **deleteFields** is as:

List<String> deleteFields = new ArrayList<>();
deleteFields.add(uploadDocumentList-placeOfIssue);
deleteFields.add(auditTrail-submissionLat);

As shown the list contains two fields separated by a hyphen, the first field is the object name of the field in LeadDetailsSRO. And, the second field is the field in the object of the first field.

For eg, in auditTrail-submissionLat: auditTrail is the object of class AuditTrailSRO which is a field of LeadDetailsSRO and submissionLat is the field present in AuditTrailSRO as :

public class AuditTrailSRO {

    private String creationAppVersion;
    private String creationLat;
    private String creationLong;
    private String creationClient;
    private String submissionLat;
    private String submissionLong;
    private String submissionAppVersion;
} 

Please suggest a way using Java reflection to delete all the fields of mergeDiff which are present in deleteList.





Aucun commentaire:

Enregistrer un commentaire