Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.