Hello,
Finally, I use this kind of code :
protected <T> T call(String uri, Class<T> c) throws BusinessException {
WebResource res = new Client().create().resource(url);
ClientResponse cresp = res.get(ClientResponse.class);
InputStream respIS = cresp.getEntityInputStream();
try {
JAXBContext jCtx = JAXBContext.newInstance(c, BeanError.class);
Object entity = jCtx.createUnmarshaller().unmarshal(respIS);
if(entity instanceof BeanError) {
BeanError error = (BeanError) entity;
throw new BusinessException(error);
} else {
return (T) entity;
}
} catch (JAXBException e) {
throw(new BusinessException(e));
}
}
Stéphane
________________________________
De : stephane.jeanjean_at_orange-ftgroup.com [mailto:stephane.jeanjean_at_orange-ftgroup.com]
Envoyé : lundi 6 décembre 2010 18:12
À : users_at_jersey.java.net
Objet : [Jersey] Multiple return type with Jersey and JaxB
Hi,
I'm using Jersey as Client API to call REST Services. I'm using JaxB entities to get the responses.
The services return a different entity if there is an error. So I have to 2 JaxB classes with an @XmlRootElement : one for my business class and one for the error. But I don't know how to use 2 classes with Jersey Client API :(
Do you have an idea to manage this kind of REST call, please ?
I found this topic which is exactly my issue :
http://stackoverflow.com/questions/2025997/multiple-return-type-in-jersey-client-request
But I can't change the REST service as proposed in the answer, it's not mine.
Thanks,
Stéphane