1

Hello guys I am new to spring and rest, I wanted to create a small module in which a user submits some values lets say first-name, last name etc from UI and the request goes to a REST service which generates a file or .xml file having that data serialized into xml format. Its kind of xml bean serialization. Can anybody tell how this can be achieved. A sample code would be a great help. thanks

1 Answer 1

0

Have a look at the tutorial here: Build RESTful web services with the Spring.

From tutorial:

In rest-servlet.xml it tells to use Jaxb2Mashaller for object XML mapping:

<bean id="jaxbMarshaller"
class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
    <list>
        <value>dw.spring3.rest.bean.Employee</value>
        <value>dw.spring3.rest.bean.EmployeeList</value>
    </list>
</property>

And in getEmployee it demonstrate how to receive REQUEST parameters and pass them to getEmployee method and then employee object as serialized XML response. You can easily modify this getEmployee method to save serialized employee object to .xml file instead of sending it as response.

@Controller
public class EmployeeController {
    @RequestMapping(method=RequestMethod.GET, value="/employee/{id}")
    public ModelAndView getEmployee(@PathVariable String id) {
        Employee e = employeeDS.get(Long.parseLong(id));
        return new ModelAndView(XML_VIEW_NAME, "object", e);
    }
}
1
  • I will try this and will let you know :)
    – Dhruv
    Mar 17, 2012 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.