cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sudheer-3 <sudheer.t...@gmail.com>
Subject JAXB only converting the base class not the derived class
Date Tue, 10 Aug 2010 11:21:38 GMT

We have implemented RESTFul service using Apache CXF. Used JSON as the
communication between our GWT client and RESTFul server.

Our DTOs are having structure Similar to below. Every DTO should extend
BaseDTO.

@XmlRootElement(name = "BaseDTO")
public class BaseDTO implements Serializable {

    private String UUID;
    public String getUUID() {
        return UUID;
    }
    public void setUUID(String UUID) {
        this.UUID = UUID;
    }
}

@XmlRootElement(name = "Agent")
public class Agent extends BaseDTO {

    private String description;
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
}

We have configured JSONProvider in spring-config.xml as below

   <jaxrs:server id="restServer" address="/services/">
        <jaxrs:serviceBeans>
            <ref bean="agentService"/>
        </jaxrs:serviceBeans>
        <jaxrs:extensionMappings>
            <entry key="feed" value="application/atom+xml"/>
            <entry key="json" value="application/json"/>
            <entry key="xml" value="application/xml"/>
            <entry key="html" value="text/html"/>
        </jaxrs:extensionMappings>
        
        <jaxrs:providers>
            <bean class="org.apache.cxf.jaxrs.provider.JSONProvider">
                <property name="writeXsiType" value="false" />
                <property name="readXsiType" value="false" />
                <property name="jaxbElementClassMap" value="" />
            </bean>
        </jaxrs:providers>
    </jaxrs:server>


Methods from AgentService.java returns List<Agent> and we put this in a
common response format defined below and constructs response using Response
(javax.ws.rs.core.Response.ok(UIServiceResponse<T>)).

@XmlRootElement(name = "UIServiceResponse")
public class UIServiceResponse<T> {

    private UIException exception;
    private List<T> result;

    public UIException getException() {
        return exception;
    }
    public void setException(UIException exception) {
        this.exception = exception;
    }
    public List<T> getResult() {
        return result;
    }
    public void setResult(List<T> result) {
        this.result = result;
    }
}


The problem is, everything works fine if we include
@XmlSeeAlso({Agent.class}) to UIServiceResponse. But when we remove we are
asked to provide information about the return classes.

This UIServiceResponse is used from multiple projects and having @XmlSeeAlso
included for every DTO we create is difficult and not a good approach.

Is there any approach that works without using @XmlSeeAlso and gets derived
class data to client? Any help is really appreciated.

Hope I did not confuse :)
Thank you
-- 
View this message in context: http://cxf.547215.n5.nabble.com/JAXB-only-converting-the-base-class-not-the-derived-class-tp2418721p2418721.html
Sent from the cxf-user mailing list archive at Nabble.com.

Mime
View raw message