i found myself in a situation where i need to get some data with POST on my server and do some simple stuff with it. But it keeps saying 415 Unsupported Media Type when i try to test it with www.hurl.it website.
This is my json that i am sending:
{
"pictures": {
"picture": [
{
"id": "1",
"name": "10_aut_linen_male_less_student_work_yellow_n_cold.png"
},
{
"id": "2",
"name": "10_aut_linen_male_less_student_work_yellow_n_mild.png"
},
{
"id": "3",
"name": "10_aut_linen_male_less_student_work_yellow_n_hot.png"
}
]
}
}
this is the model class:
package com.models.sm7;
import java.util.ArrayList;
import java.util.List;
public class Sm7Pictures {
private Pictures pictures;
public Pictures getPictures() {
return pictures;
}
public void setPictures(Pictures pictures) {
this.pictures = pictures;
}
public class Pictures {
private List<Picture> picture = new ArrayList<Picture>();
public List<Picture> getPicture() {
return picture;
}
public void setPicture(List<Picture> picture) {
this.picture = picture;
}
}
public class Picture {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
This is my service class :
@Path("sm7Service")
public class Sm7Service {
Sm7DAO sm7DAO = new Sm7DAO();
@GET
@Path("/testSm7")
@Produces(MediaType.TEXT_PLAIN)
public String testSm (){
return "Hello";}
@POST
@Path("/checkPictures")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String getPictures(Sm7Pictures picture){
System.out.println("pokrenuto");
return "Hello";}
}
the DAO class is where i will do all my logic, but for testing purpouses i've just put text plain... I am really banging my head over this :S because it is simple but i can not get it to work. my bet is that it has something to do with the model class? Please help!
解决了这个问题,必须将{}
放在@Consumes(MediaType.APPLICATION_JSON)
就像@Consumes({MediaType.APPLICATION_JSON})
。
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.