Jersey Exception : SEVERE: A message body reader for Java class

后端 未结 15 1930
说谎
说谎 2020-11-29 11:08

I have a Jersey based Rest WS which outputs JSON. I am implementing a Jersey Client to invoke the WS and consume the JSON response. The client code I have is below



        
15条回答
  •  心在旅途
    2020-11-29 11:26

    Just add below lines in your POJO before start of class ,and your issue is resolved. @Produces("application/json") @XmlRootElement See example import javax.ws.rs.Produces; import javax.xml.bind.annotation.XmlRootElement;

     /**
     * @author manoj.kumar
     * @email kumarmanoj.mtech@gmail.com
     */
     @Produces("application/json")
     @XmlRootElement  
     public class User {
    
     private String username;
     private String password;
     private String email;
     public String getUsername() {
     return username;
     }
     public void setUsername(String username) {
         this.username = username;
     }
     public String getPassword() {
         return password;
     }
     public void setPassword(String password) {
         this.password = password;
     }
     public String getEmail() {
        return email;
     }
     public void setEmail(String email) {
        this.email = email;
     }
    
    }
    add below lines inside of your web.xml
    
        com.sun.jersey.api.json.POJOMappingFeature
        true
      
    Now recompile your webservice everything would work!!!
    

提交回复
热议问题