My course pojo is ;
public class Course {
private int cid;
private String name;
private String code;
private int credit;
//Getters Setters
}
service :
@RequestMapping(value="/addcourse" , method=RequestMethod.POST)
public @ResponseBody Response<Course> addCoursetoUser(@RequestBody Course course, @RequestBody User user) throws SQLException{
if(new CourseDAO().addCoursetoUser(course, user))
return new Response<>(...);
else
return new Response<>(...);
}
i am trying to send this json values to my web service, but i am getting this error : org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "cid" (Class com.spring.model.Course), not marked as ignorable
{
"id" :3,
"name" : "Algorithms",
"code" : "COM367",
"credit" : 3,
"cid" : 28,
"username" : "selin",
"password" : "ssgg"
}
I have tried a lot of jsons but I always get this error. Thanks in advance..
You can't. You will need to wrap your two objects into a single object (maybe CourseUser
or CourseUserRequest
).
Also that error implies your Course
class is missing the cid
field in the Java model.
First of all you need to write getter and setter method for all class members which you have declared in your pojo :
eg :
public class Course {
private int cid;
public int getCid()
{
return this.cid ;
}
public void setCid(int cid)
{
this.cid=cid;
}
}
Second You can not have two request body param in your post method here either you need to define a parent pojo which has Course and User Pojo like this
public class MyClass{
private Course course ;
private User user ;
// getter setter for User and Course
}
Of Course your json will be change if you use this like :
{
"course.id" :3,
"course.name" : "Algorithms",
"course.code" : "COM367",
"course.credit" : 3,
"course.cid" : 28,
"user.username" : "selin",
"user.password" : "ssgg"
}
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.