Covariant method selection using JAXB entity class type
- Dominant language
- Java
- Stars
- 400
- Forks
- 143
- PR merge metrics
- No merged PRs in 30d
Description
In some situations it makes sense to have covariant method selection performed by JAXB entity class type.
Example:
In JAX-RS 1.0 it is possible to manually implement covariant method selection by code similar to this one:
```
@GET public T covariantMethod(InputStream e, @Context Providers providers) JAXBException {
JAXBContext c = providers.getContextResolver(JAXBContext.class, APPLICATION_XML_TYPE).getContext(Some.class);
Object o = jaxbContext.createUnmarshaller().unmarshal(e);
if (o instanceof V)
return covariantMethod((V) jaxbObject);
if (o instanceof W)
return covariantMethod((W) jaxbObject);
return Response.status(BAD_REQUEST).build();
}
private Response covariantMethod(V e) {...process V...}
private Response covariantMethod(W e) {...process W...}
```
As can be seen, within the automatic selection using HTTP verb and MediaType, this adds another level of selection based on the actual entity type.
To prevent manual code like the above, it would be great if a future JAX-RS specifiction would directly support this type of selection. With that in place, the above code could get reduced to this...
```
@GET public T covariantMethod(V e) {...process V...}
@GET public T covariantMethod(W e) {...process W...}
```
...which obviously is much smarter to read and write and rather unambiguous.
#### Affected Versions
[1.1]
Contributor guide
Assessment
This issue has not been assessed yet.