2

Tech Stack: Java 1.6, JPA (Hibernate 3), Spring 3, Oracle 11g

Hello,

We are currently refactoring our code to move away from SOAP based web-services to REST. I've got loads of XSD, these were used for SOAP based WS. And there are tons of JAXB classes generated using these schema files.

My question is can I use the same JAXB classes for REST (in and out) or not. I've no experience with REST.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
adi
  • 1,711
  • 3
  • 29
  • 50

1 Answers1

4

It's better than you might think. Just take your JAXB object that you used previously for SOAP endpoints and return them from controllers:

public @ResponseBody JAXBElement<JaxbResponseType> 
controllerMethod(@RequestPayload JAXBElement<JaxbRequestType> request) {
    //...
}

Spring, seeing JAXB annotations, will automatically marshall them to XML and JSON. This should be a good starting point, not to mention your REST services will have similar structure to SOAP.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • @adi: yes, just include `jackson*.jar` in your CLASSPATH. – Tomasz Nurkiewicz Jul 24 '12 at 14:25
  • 1
    I've not mentioned, but I am using JAX-RS (RESTEasy), hope that will not make a difference?? na ddo I need those @ResponseBody and other annotations? I've not seen those in the examples, I've read so far. – adi Jul 24 '12 at 14:32
  • @adi: you mentioned Spring, these annotations come from Spring MVC. With JAX-RS it looks the same, just return JAXB objects from your endpoint methods. That's it! – Tomasz Nurkiewicz Jul 24 '12 at 14:37