CXF JAXRS | Complex response types are missing in generated wadl

We use cxf 2.5.2 along with spring to expose and consume sedative services. To propagate the service interface classes, we started using the wadl2java target (which generates interface classes based on this wadl file)

The generated wadl does not contain the correct response type, due to which, I think, the generated interfaces have a "Response" as the return type.

Ex. if the restful get method returns "List", the generated wadl contains only the following segment:

<response><representation mediaType="application/json"/></response>

and the corresponding interface generated from this wadl file contains the return type as "Response"

Can anyone suggest what needs to be done to prevent the loss of the actual type of response? Are there any annotations (e.g. ElementClass? How to use them?) Or suppliers?

Current Code:

@GET
@Path("/itemsForCategory")
@Produces("application/json")
@Description("getItemsForCategory")
public List<Item> getItemsForCategory(@QueryParam("category")String category) {
+5
source share
2 answers

The general type of "Response" returned response does not seem to be related to the fact that you are trying to return a list. That is, even using "Item", since the return type will result in a method in the generated interface with the return type "Response". To fix this, you need to add the element attribute in response to the WADL resource:

<response><representation mediaType="application/json" element="item"/></response>

, WADL , JAX-RS . . ( ) (, ItemList), .

( WADL). , , .

, JAX-RS " ". pom ( wadl2java) wadl github. (, BookstoreidResource.java).

+2

, .. WSDL, , , . , , , - . , , .

, , User, BaseObject, -. . .

@WebService
public interface MyService
{
    // Various @WebMethods here

    /**
     * This method should not be used. This is a workaround to ensure that
     * User is known to the JAXB context. Otherwise you will get exceptions like this:
     * javax.xml.bind.JAXBException: class java.util.User nor any of its super class is known to this context.
     * Or it will assume that using BaseObject is OK and deserialisation will fail
     * since BaseObject is abstract.
     * This issue occurs because the classes available to the JAXB context
     * are loaded when the endpoint is published. At that time it is not known
     * that User will be needed since it is not explicitly referenced
     * in any of these methods. Adding user here will cause it to be added to
     * the context.
     * @param user
     * @return
     */
    @WebMethod
    void dummy(@WebParam(name="user") User user);
}

, , , , , , - .

, .

-1

All Articles