Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@Path({id}/tweet)
@POST
@Consumes("application/json")
public Response postTweet(Tweet aTweet){
//Tweet is a custom domain object
}
@Provider
@Consumes("application/json")
public TweetReader implements MessageBodyReader<Tweet>{
@Override
public Tweet readFrom(Class<Tweet> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String,String> headers, InputStream payload){
//use the InputStream (e.g. Tweet in form of JSON payload) and convert it into the domain representation of a Tweet
//which will then be injected into the postTweet method
Tweet domainObj = .... ;
return domainObj;
}
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType){
//use the contextual info - type, genericType and mediaType to determine if this message body reader can actually return the desired Java type
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment