5

Application / JSON is an unsupported media type in a web service

 3 years ago
source link: https://www.codesd.com/item/application-json-is-an-unsupported-media-type-in-a-web-service.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Application / JSON is an unsupported media type in a web service

advertisements

I am trying to create a restful-jersey webservice. I have to pass JSON object to the webservice.

    @POST
    @Path("/saveVehicleTrackingData")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.TEXT_PLAIN)
    public String saveVehicleTrackingData(VehicleTracking vehicleTracking) {
        return vehicleTracking.toString();
    }

When I try try to make request to the service, it says HTTP Status 415 - Unsupported Media Type. Please help. Also, what should be the type of single argument of the method saveVehicleTrackingData.

PS: I am using POSTMAN to make http request. http://goo.gl/vwXNXQ

e5qTv.jpg

UPDATE : As pointed out by peeskillet, the missing thing here is JSON Provider. The next challenge that I have is, how to integrate the JSON Provider in my project. After researching a little, I found FasterXML jackson as one of the JSON provider.


nw4ZO.png

This image is just for reference. I just had it from another post.

Basically when you use raw, it will default to text/plain. The JSON in the drop down, is simply to select syntax highlighting. You still need to set the Content-Type header to application/json. You can click on the Headers button and add it.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK