With the use of CastorMarshaller class, we can achieve marshal a java object into XML code and vice-versa of it with the help of using castor. The castor is the implemented class for Marshaller and Unmarshaller interfaces within it, thus it does not require other further configurations by its default. The most common example of Spring and Castor Integration is ‘Marshalling the Java Object into the XML.
Implementation: We need to create the following files for marshaling Java objects within the XML use of Spring with the Castor:
The requirement of Jar files is as follows:
Note: For Running this example, we need to load the following files:
Spring Core jar files
Spring Web jar files
A. File: Worker.java
This file defines the three properties that are id, name, and salary of worker with setters and getters.
// Java Program to Illustrate Worker Class
// Class data members
// Worker id
// Worker name
// Worker Salary
this.id = id;
this.name = name;
this.sal = sal;
B. File: aplcontext.xml
this file is defining a bean castorMarshallerBean as ‘Worker class’ is bounded at with the OXM framework
Please Login to comment...