membersound
membersound

Reputation: 86905

How to autogenerate JAXB annotations from POJOs?

I'd like to offer a simple webservice that takes a complex object as input parameter. The complex object is a simple pojo, and I want to expose all the member fields via soap.

class Customer {
    private int id;
    private String name;
    private List<String> values;
    private XMLGregorianCalendar birthDate;
}

@WebService
public clcass CustomerService {

    @WebMethod
    public String process(@WebParam(name = "customer") Customer customer) {

    }
}

Is there any plugin/mechanism that can auto-generate the missing JAXB annotations on the Customer class so that JAX-WS can publish the webservice?

Upvotes: 1

Views: 162

Answers (1)

Xstian
Xstian

Reputation: 8282

Java First Development: I think that you must add all annotations necessary to work by JAXB.

Contract First Development: If you have a WSDL definition and XML definition you can use these maven plugin.

<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>

and

<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>

that generates all annotations for you.

I think which another solution is that you generate an XSD from your java class(schemagen plugin), in order to approach to "Contract First Development".

I hope I've given you all the answers about your question.

Upvotes: 3

Related Questions