Rajar R
Rajar R

Reputation: 149

Custom media type Consume rest call post operation

Need to consume rest service which as below. jersy client

@POST
@Produces("application/vnd.app.mail-service+json")
@Consumes("application/vnd.app.mail-service+json")
public TempResponse submit(TempRequest request) {

}

Here the TempRequest is JAXB object.

To consume the service from javascript. have set the Accept and Content-Type as "application/vnd.app.mail-service+json" and sending the json request

{
  "TempRequest" :{
       "TempR1" : {
          "id" : "1212",
          "name" : "app",
        }
  }
}

On submitting request, the received request body in the Service application is empty, if i try with "+xml" in both consumes and produces and change content type the request body is not empty.

Using Jersy-cleint and jax-rs with deployed in spring 4.3.7 application with jacson-core and asl - 1.19.3

Upvotes: 0

Views: 278

Answers (1)

Ravi
Ravi

Reputation: 31397

I'm not sure why are you using application/vnd.app.mail-service+json instead of application/json.

Same needs to be changed to

@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)

And I hope, you have similar changes in TempRequest class, which is a JAXB class.

@XmlRootElement(name="TempRequest")
@XmlAccessorType(XmlAccessType.FIELD)
public class TempRequest {

    @XmlElement(name="TempR1") 
    private TempR1 temp;

    public TempRequest() {}

    // Getter and setter methods
    // ...
}

Upvotes: 0

Related Questions