简体   繁体   中英

Error converting JSON to object via jersey

I've created DynamicWeb project (not maven) in eclipse with Target server Tomcat 7.

In location '\\WebContent\\WEB-INF\\lib' I placed jars:
jersey-json-1.19.jar
jersey-bundle-1.19.jar
jersey-core-1.19.jar

in web.xml I have:

<init-param>
    <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
    <param-value>true</param-value>
</init-param>

Pojo:

@XmlRootElement(name = "input")
public class InputOb {
    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}

Rest resource:

@Path("/add")
public class AddOb {

    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)   
    public Response add(InputOb input) {
        ....        
    }   
}

When I try to call it, I am getting:

SEVERE: A message body reader for Java class datatypes.InputOb, and Java type class datatypes.InputOb, and MIME media type application/json was not found.

Try to add your dependencies through pom.xml and use maven to run. Maybe something goes wrong with the jars.

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