Created
January 8, 2015 21:08
-
-
Save abhirockzz/4204823873f9f6d19c39 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
@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