vivek
vivek

Reputation: 4919

How to post an Object in JAX-RS

I had code like this:

Service class

@POST
@Path("/updateProduct.htm")
@Consumes("application/json")
@Produces(MediaType.APPLICATION_JSON)
public String updateProduct(ProductRow productRow) {
    // ...
}

Client class

WebClient client = WebClient.create(getBaseUrl() + "/inventory/updateProduct.htm").accept(MediaType.APPLICATION_JSON);
client.post(productRow);

ProductRow class

public class ProductRow {
    private Long id;
    private String name;
    // getter and setter methods
    //...
}

But it is throwing org.apache.cxf.jaxrs.client.ClientWebApplicationException: .No message body writer has been found for class : class com.myfashions.ui.model.ProductRow, ContentType : application/xml.. Any idea on how to do this? What are the changes need to be done to ProductRow class?

Upvotes: 3

Views: 118

Answers (1)

vicky
vicky

Reputation: 1046

Add annotation @XmlRootElement above ProductRow class

Upvotes: 2

Related Questions