Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created January 8, 2015 21:08
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 abhirockzz/4204823873f9f6d19c39 to your computer and use it in GitHub Desktop.
Save abhirockzz/4204823873f9f6d19c39 to your computer and use it in GitHub Desktop.
@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