0

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..

1
  • when i define a new class which has Course and User pojo like that : public class CourseUser { private User user; private Course course; //Getters Setters } i changed my post method like that : @RequestMapping(value="/addcourse" , method=RequestMethod.POST) public @ResponseBody Response<Course> addCoursetoUser(@RequestBody CourseUser courseUser) throws SQLException{ .. } And i changed my json like { "course.id" : 3, "course.name" : "Algorithms", .... } But still i am getting same error : Unrecognized field "course.id" not marked as ignorable Commented Aug 28, 2016 at 6:14

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.