Right Now in my application input data(City data) coming from database. I follow the below procedure for processing the input. - read the data from database and create the CityDTO object(Class=CityDTO) - map DTO to business object (CityBO)
But now, Client will send city data with Json file using webservice. Now i have CityJson object(Class = CityJSon) and i want to map CityJSon to CityBO
Please refer the below code snippet for understanding :
***** Database or DTO object *****
Public Class CityDTO {
Public String name;
public <List>AreaDTO;
}
Public Class AreaDTO {
Public String name;
public String zipcode;
}
***** Business or Domain object *****
Public Class CityBO{
Public String name;
public <List>AreaBO;
}
Public Class AreaBO{
Public String name;
public String zipcode;
}
***** Mapping of CycleDTO to CycleBO *****
Class DBmapper {
public void CityBO mapToCityBO(CityDTO citydto){
CityBO citybo = new cityBO();
citybo.setName(citydto.getName);
citybo.setAreaBO(mapAreaBO(citydto.getAreaDTO));
}
public List<AreaBO>mapAreaBO(List<AreaBO> listOfAreadto){
List<AreaBO> listOfAreaBO = new ArrayList<AreaBO>
for(AreaDTO areadto : listOfAreadto){
AreaBO areaBO = new AreaBO();
areaBO.setName(areadto.getname());
areaBO.setZipCode(areadto.getZipCode());
}
}
}
Now i have CityJson class/object and i want to map CityJson object to CityBO object in future i may have CityXML object which again need to map into CityBO.
Two or more differnt input object and wanted to map in same business object. How can i achive this so that if in future client add more input type then my application code must be maintained.?