[
https://issues.apache.org/jira/browse/CXF-7545?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16250581#comment-16250581
]
Evaristo Wychoski Benfatti edited comment on CXF-7545 at 11/14/17 12:43 AM:
----------------------------------------------------------------------------
Sample classes
{code:java}
@XmlRootElement(namespace = "http://example.com")
public static class Super {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static class SuperResource<T extends Super> {
@PUT
@Path("set")
@Produces("application/xml")
@Consumes("application/xml")
public T set(T transfer) {
return transfer;
}
}
@XmlRootElement(namespace = "http://example.com")
public static class Actual extends Super{}
public static class ActualResource extends SuperResource<Actual> {}
{code}
WADL generated before fix:
{code:xml}
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xs="http://www.w3.org/2001/XMLSchema"><grammars><xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://example.com">
<xs:import/>
<xs:element name="super" type="super"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example.com" attributeFormDefault="unqualified"
elementFormDefault="unqualified" targetNamespace="http://example.com">
<xs:complexType name="super">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars><resources base="http://example"><resource path="/"><resource
path="set"><method name="PUT"><request><representation
mediaType="application/xml"/></request><response><representation
mediaType="application/xml"/></response></method></resource></resource></resources></application>
{code}
WADL generated after fix:
{code:xml}
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:prefix1="http://example.com"><grammars><xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://example.com">
<xs:import/>
<xs:element name="actual" type="actual"/>
<xs:element name="super" type="super"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example.com" attributeFormDefault="unqualified"
elementFormDefault="unqualified" targetNamespace="http://example.com">
<xs:complexType name="actual">
<xs:complexContent>
<xs:extension base="super">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="super">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars><resources base="http://example"><resource path="/"><resource
path="set"><method name="PUT"><request><representation
mediaType="application/xml"
element="prefix1:actual"/></request><response><representation
mediaType="application/xml"
element="prefix1:actual"/></response></method></resource></resource></resources></application>
{code}
was (Author: evaristowb):
Sample classes
{code:java}
@XmlRootElement(namespace = "http://example.com")
public static class Super {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static class SuperResource<T extends Super> {
@PUT
@Path("set")
@Produces("application/xml")
@Consumes("application/xml")
public T set(T transfer) {
return transfer;
}
}
@XmlRootElement(namespace = "http://example.com")
public static class Actual extends Super{}
public static class ActualResource extends SuperResource<Actual> {}
{code}
Xml generated before:
{code:xml}
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xs="http://www.w3.org/2001/XMLSchema"><grammars><xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://example.com">
<xs:import/>
<xs:element name="super" type="super"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example.com" attributeFormDefault="unqualified"
elementFormDefault="unqualified" targetNamespace="http://example.com">
<xs:complexType name="super">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars><resources base="http://example"><resource path="/"><resource
path="set"><method name="PUT"><request><representation
mediaType="application/xml"/></request><response><representation
mediaType="application/xml"/></response></method></resource></resource></resources></application>
{code}
Xml generated after:
{code:xml}
<application xmlns="http://wadl.dev.java.net/2009/02"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:prefix1="http://example.com"><grammars><xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://example.com"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://example.com">
<xs:import/>
<xs:element name="actual" type="actual"/>
<xs:element name="super" type="super"/>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://example.com" attributeFormDefault="unqualified"
elementFormDefault="unqualified" targetNamespace="http://example.com">
<xs:complexType name="actual">
<xs:complexContent>
<xs:extension base="super">
<xs:sequence/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="super">
<xs:sequence>
<xs:element name="id" type="xs:int"/>
<xs:element minOccurs="0" name="name" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</grammars><resources base="http://example"><resource path="/"><resource
path="set"><method name="PUT"><request><representation
mediaType="application/xml"
element="prefix1:actual"/></request><response><representation
mediaType="application/xml"
element="prefix1:actual"/></response></method></resource></resource></resources></application>
{code}
> Problem to generate WADL when a implementation of generic type is used
> ----------------------------------------------------------------------
>
> Key: CXF-7545
> URL: https://issues.apache.org/jira/browse/CXF-7545
> Project: CXF
> Issue Type: Bug
> Components: JAX-RS
> Affects Versions: 3.1.9, 3.2.0
> Environment: All plataforms
> Reporter: Evaristo Wychoski Benfatti
> Assignee: Sergey Beryozkin
> Priority: Minor
> Labels: patch
> Fix For: 3.1.14, 3.2.1
>
>
> When we have the following scenario, the the wadl is not properly generated.
> {code:java}
> public abstract class BaseEntity { ... }
> public class Entity extends BaseEntity { ... }
> public abstract class SuperResource<T extends BaseEntity>
> {
> @POST
> @Path("/method")
> public T resourceMethod(T param){ ... }
> }
> @Path("/resource")
> public class ChildResource extends SuperResource<Entity> { ... }
> {code}
> The generation to ChildResource only exposes the methods to {{BaseEntity}}
> instead of exposing correctly the specialized type {{Entity}}.
> This problem occurs on
> {{rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java}}
> file when it evaluates generic types.
> The solution is considering the TypeVariable to specialized types as follow:
> {code:java}
> // Line 1047 instead of this
> - if (theActualType == Object.class && !(genericType
> instanceof Class)) {
> // using the following lines
> + if ((theActualType == Object.class && !(genericType
> instanceof Class))
> + || (genericType instanceof
> TypeVariable)) {
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)