0

I have two package and both package have some class with same name in my project.I had successfully created XML file for class with same name using spring oxm but when i try to convert from XML to class then it shows the following error :

java.lang.ClassCastException: com.tmk.loanprocessing.core.template.overdraft.Recommendation cannot be cast to com.tmk.loanprocessing.template.autoloan.Recommendation

Spring configuration for XML marshalling and unmarshalling is here :

<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
   <property name="targetClasses">
     <array>
       <!-- For Overdraft Loan Entity -->
       <value>com.tmk.loanprocessing.core.template.overdraft.CustomerInfo</value>
       <value>com.tmk.loanprocessing.core.template.overdraft.CompanyInformation</value>
       <value>com.tmk.loanprocessing.core.template.overdraft.SiteVisit</value>
       <value>com.tmk.loanprocessing.core.template.overdraft.Proposal</value>
       <value>com.tmk.loanprocessing.core.template.overdraft.Security</value>
       <value>com.tmk.loanprocessing.core.template.overdraft.CICL</value>
       <value>com.tmk.loanprocessing.core.template.overdraft.Financials</value>
       <value>com.tmk.loanprocessing.core.template.overdraft.Recommendation</value> 
       <value>com.tmk.loanprocessing.core.template.overdraft.SectorInfo</value>

       <!-- For Auto Loan Entity -->
       <value>com.tmk.loanprocessing.template.autoloan.BasicInfo</value> 
       <value>com.tmk.loanprocessing.template.autoloan.Company</value>
       <value>com.tmk.loanprocessing.template.autoloan.SiteVisit</value> 
       <value>com.tmk.loanprocessing.template.autoloan.Security</value>    
       <value>com.tmk.loanprocessing.template.autoloan.Financial</value>
       <value>com.tmk.loanprocessing.template.autoloan.Recommendation</value>
     </array>
   </property>
</bean>

And marshalling and unmarshalling code is :

public void convertFromObjectToXML(Object object,Object xmlPath){
    File file = null;
    FileOutputStream fos = null;
    String className = object.getClass().getSimpleName();
    try{
        file = new File((String)xmlPath);
        file.mkdirs();
        fos = new FileOutputStream(xmlPath+className+".xml");
        marshaller.marshal(object, new StreamResult(fos));

    }catch(Exception ex){
        System.out.println("Error occured while marshalling");
        ex.printStackTrace();
    }

}

public Object convertFromXMLToObject(File xmlPath){

    FileInputStream fileInputStream = null;
    try{
        fileInputStream = new FileInputStream(xmlPath);
        return unmarshaller.unmarshal(new StreamSource(fileInputStream));
    }catch(Exception ex){
        ex.printStackTrace();
    }
    return null;
}

How could i get rid of this error ? Any suggestion please ?

subash048
  • 31
  • 1
  • 1
  • 5

0 Answers0