Skip to content

Instantly share code, notes, and snippets.

@marianogonzalez
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marianogonzalez/dd19b6faf5c57ca981dd to your computer and use it in GitHub Desktop.
Save marianogonzalez/dd19b6faf5c57ca981dd to your computer and use it in GitHub Desktop.
package com.my.project.jersey.readers;
@Provider
public static class MyBeanMessageBodyReader implements MessageBodyReader<MyBean> {
@Override
public boolean isReadable(Class<?> type, Type genericType,
Annotation[] annotations, MediaType mediaType) {
return type == Person.class;
}
@Override
public MyBean readFrom(Class<MyBean> type,
Type genericType,
Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, String> httpHeaders,
InputStream entityStream)
throws IOException, WebApplicationException {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(MyBean.class);
return (Person) jaxbContext.createUnmarshaller()
.unmarshal(entityStream);
return myBean;
} catch (JAXBException jaxbException) {
throw new ProcessingException("Error deserializing a Person.",
jaxbException);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment