[Jersey] Question on custom MessageBodyReader?

From: <>
Date: Fri, 26 Dec 2014 07:05:31 +0000 (UTC)

Hi All,
I have a question related with MessageBodyReader in the context of
JAX-RS client API. In my scenario, I have my own custom
MessageBodyReader for un-marshalling Json to Java object.

Message body reader code is as follows,

        public Book readFrom(Class<Book> clazz, Type type, Annotation[]
                MediaType mediaType, MultivaluedMap<String, String>
                InputStream stream) throws IOException,
WebApplicationException {
                JsonReader jsonReader = Json.createReader(stream);
                JsonObject jsonObject = jsonReader.readObject();
                String title = jsonObject.getString("title");
                String author = jsonObject.getString("author");
                return new Book(title, author);

BookResource code:
        public String createBook(Book book) {
                System.out.println("Here book: " + book);
                return "Created successfully";

REST client code:
        public void testBookJsonUnMarshaller() {
                WebTarget webTarget ="http://localhost:8080/restfullab/api").path("books");
                JsonObject jsonObject = Json.createObjectBuilder()
                        .add("title", "God of small things")
                        .add("author", "Roy").build();
// Form form = new Form();
// form.param("book", jsonObject.toString());
// Book book = new Book("God of small things", "Roy");
                Response response =
                System.out.println("Respose code: " +
                System.out.println("Respose value: " +

I am able to successfully call my POST method using the above client
code. The given JSON object is properly understood by the resource

Now my question is how to call my POST method using normal REST client
(Browser client) without using the JAX-RS client code? How the JSON
object can be passed along with the request? Any clue???