Not my area, but I think you can register a custom  
ContextResolver<JAXBContext>  for the service that would allow you to create 
the JAXBContext that is used.   See:
http://cxf.547215.n5.nabble.com/cxf-rest-how-to-deal-with-xs-any-
td2281907.html#a2370139

for an example.

Dan

On Tuesday 10 August 2010 7:21:38 am Sudheer-3 wrote:
> 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

-- 
Daniel Kulp
[email protected]
http://dankulp.com/blog

Reply via email to