Search code examples
javaarraysobjectcxfpojo

CXF response objects referencing objects


I have a project containing drivers, their functions, and their arguments. Simplified:

Controller

@WebService  
Device[] getDevices() @WebMethod  

Device

String getName() @WebMethod  
Function[] getFunctions() @WebMethod

Function

String getName() @WebMethod  
Argument[] getArguments() @WebMethod

Argument

...

These POJO objects already exist. I am using the Eclipse tools to generate CXF code.

At the moment, Controller.getDevices is returning a list of devices. However, these objects only contain the field "name". The function references are completely stripped.

From reading the (limited?) information available on this subject, I found I should annotate the classes with XMLRootElement. However, this doesn't change anything. Or should every class be it's own WebService?

I am searching for pointers to information or documentation on how to correctly implement a system like this in CXF. I'm hoping I'm on the right path, but if I'm not, pointers to a workable design pattern would also be very helpfull!


Solution

  • First off, the @WebMethod annotations are only needed on the actual service, not each of the pojo objects.

    For the second problem, make sure the Device has both getter and setter methods for the Functions. Also make sure the Function object has a default constructor.