Can someone help me to create a generic method that validates common fields/variables comes from multiple objects, if that is possible? The below code validates some bunch of variables/fields from a schema object, so here the requirement is I have two different schema objects which has common Fields/variables, Is it possible to validate these variables in more generic way. In below code there is two events FI & Profile (Note: Future can be more events like these) these are two different schema objects but has same fields/variables of same Object "Types". public class RequestValidation { public void validateRequest(EventRequest eventRequest) { //FI Event FIEventProcessorImpl fiEventProcessor = new FIEventProcessorImpl(); FIEventSchema fiEvent = fiEventProcessor.getFiEventSchema(eventRequest); //Party data Validation String partyFName = null; String partyLName = null; String partyEmail = null; String partyId = null; if (null != fiEvent.getParty()) { partyId = fiEvent.getParty().getPartyId(); if (null != fiEvent.getParty().getPartyName() && null != fiEvent.getParty().getPartyName().getName()) { partyFName = fiEvent.getParty().getPartyName().getName().getGivenName(); partyLName = fiEvent.getParty().getPartyName().getName().getSurname(); if (null == partyFName && null == partyLName) { Map<String, Object> nameMap = fiEvent.getParty().getPartyName().getName() .getAdditionalProperties(); if (!nameMap.isEmpty()) { partyFName = getAdditionalProperty(nameMap, "first_name"); partyLName = getAdditionalProperty(nameMap, "last_name"); } } } if (null != fiEvent.getParty().getPartyEmail()) { partyEmail = fiEvent.getParty().getPartyEmail().getEmailAddress(); if(null == partyEmail || partyEmail.isEmpty()){ //Logging missing field value logic } } } if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty() || null == partyId || partyId.isEmpty()) { //Logging missing field value logic } //Application Context data Validation String score = null; String clientId = null; if(null != fiEvent.getApplicationContext() && null != fiEvent.getApplicationContext().getContextItems()){ List<ContextItem> contextItems = fiEvent.getApplicationContext().getContextItems(); if(null != contextItems && !contextItems.isEmpty()){ socialScore = getContextValue(contextItems, "SCORE"); clientFp = getContextValue(contextItems, "CLIENT_ID"); } } if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) { //Logging missing field value logic } //ProfileChange Event ProfileProcessorImpl eventProcessor = new ProfileProcessorImpl(); ProfileEventSchema profileevent = eventProcessor.getProfileEventSchema(eventRequest); //Party data Validation if (null != profileevent.getParty()) { partyId = profileevent.getParty().getPartyId(); if (null != profileevent.getParty().getPartyName() && null != profileevent.getParty().getPartyName().getName()) { partyFName = profileevent.getParty().getPartyName().getName().getGivenName(); partyLName = profileevent.getParty().getPartyName().getName().getSurname(); if (null == partyFName && null == partyLName) { Map<String, Object> nameMap = profileevent.getParty().getPartyName().getName() .getAdditionalProperties(); if (!nameMap.isEmpty()) { partyFName = getAdditionalProperty(nameMap, "first_name"); partyLName = getAdditionalProperty(nameMap, "last_name"); } } } if (null != profileevent.getParty().getPartyEmail()) { partyEmail = profileevent.getParty().getPartyEmail().getEmailAddress(); if(null == partyEmail || partyEmail.isEmpty()){ //Logging missing field value logic } } } if (null == partyFName || partyFName.isEmpty() || null == partyLName || partyLName.isEmpty() || null == partyId || partyId.isEmpty()) { //Logging missing field value logic } //Application Context data Validation if(null != profileevent.getApplicationContext() && null != profileevent.getApplicationContext().getContextItems()){ List<ContextItem> contextItems = profileevent.getApplicationContext().getContextItems(); if(null != contextItems && !contextItems.isEmpty()){ socialScore = getContextValue(contextItems, "SCORE"); clientFp = getContextValue(contextItems, "CLIENT_ID"); } } if (null == score || score.isEmpty() || null == clientId || clientId.isEmpty()) { //Logging missing field value logic } } private String getContextValue(List<ContextItem> contextItems, String key) { String value = null; for(ContextItem contextItem : contextItems){ if(contextItem.getKey().equalsIgnoreCase(key)){ value = contextItem.getValue(); } } return value.toString(); } private String getAdditionalProperty(Map<String, ?> map, String key) { Object value = map.get(key); return value == null ? null : value.toString(); } }