简体   繁体   中英

apache wink jettison

Using Jettison provider.

 public Set getClasses() {
  Set s = new HashSet();
  s.add(DatabaseResource.class);
  return s;
  }
  public Set<Object> getSingletons() {
  Set s = new HashSet();
  JettisonJAXBProvider jaxbProvider = new JettisonJAXBProvider();
  jaxbProvider.setUseAsReader(true);
  jaxbProvider.setUseAsWriter(true);
  return s;
  }

Server Code:

 @POST
 @Consumes(MediaType.APPLICATION_JSON)
 @Produces(MediaType.APPLICATION_JSON)
 public Book post(Book inMessage) {
  System.out.println("entered post method");
      Book outMessage = new Book();
      outMessage.setAuthur("Shiva:"+inMessage.getAuthur());
      outMessage.setBookId("500");
      outMessage.setBookName("SHIVA THE GREAT");

      return outMessage;

 }

Client Code:

Resource resource = client.resource("http://localhost:8080/CoeeServer/rest/book");

  Book book = new Book();
        book.setAuthur("author--Shiva.");
        book.setBookId("500");
        book.setBookName("Shiva the great");




        Book response1  = resource.contentType(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML).post(Book.class,book);

Is this the right way to call? Can anyone has any suggestions.


I am getting the following error.

No javax.ws.rs.ext.MessageBodyWriter found for type {0} and media type {1}. Verify that all entity providers are correctly registered.

I solved my problem . Problem was with jaxb annotations just replaced with @XmlRootElement. This may help other so posting my my solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM