Last active
August 29, 2015 14:06
-
-
Save marianogonzalez/dd19b6faf5c57ca981dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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