I am running my REST service(Jersey) in Jetty.When I invoke REST method with XML media type in Response it works fine but when the media type is JSON the parent tag is missing from json response.Can someone help me how to resolve the issue?
Thanks in advance. The resource class is:
public class Service {
@Autowired
private StudentDao studentDao;
@Autowired
private TutorDao tutorDaoImpl;
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/{tutorId}")
public AllStudentSession getAllStudentForTutor(
@PathParam("tutorId") final String tutorId) {
return tutorDaoImpl.getAllAssignedStudent(tutorId);
}
}
@XmlRootElement(name = "all_student_session_info")
public class AllStudentSession {
private List<StudentSessionsResp> allStudentAssigned;
@XmlElement(name = "allStudentAssigned")
public List<StudentSessionsResp> getAllStudentAssigned() {
return allStudentAssigned;
}
public void setAllStudentAssigned(
List<StudentSessionsResp> allStudentAssigned) {
this.allStudentAssigned = allStudentAssigned;
}
}
@XmlRootElement(name = "assigned_students_tutor")
public class StudentSessionsResp {
private String childId;
private String childName;
private String parentName;
private String subject;
private String grade;
private String phoneNumber;
private AddressResp address;
private String email;
@XmlElement(name = "childId")
public String getChildId() {
return childId;
}
@XmlElement(name = "parentName")
public String getParentName() {
return parentName;
}
@XmlElement(name = "subject")
public String getSubject() {
return subject;
}
@XmlElement(name = "grade")
public String getGrade() {
return grade;
}
@XmlElement(name = "phoneNumber")
public String getPhoneNumber() {
return phoneNumber;
}
@XmlElement(name = "studentName")
public String getChildName() {
return childName;
}
@XmlElement(name = "address")
public AddressResp getAddress() {
return address;
}
@XmlElement(name = "email")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public void setChildName(String childName) {
this.childName = childName;
}
public void setAddress(AddressResp address) {
this.address = address;
}
public void setChildId(String childId) {
this.childId = childId;
}
public void setParentName(String parentName) {
this.parentName = parentName;
}
public void setSubject(String subject) {
this.subject = subject;
}
public void setGrade(String grade) {
this.grade = grade;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
The desired output is:
{
"all_student_session_info": {
"allStudentAssigned": [
{
"address": {
"city": "testcity",
"country": "testcountry",
"houseNumber": "10",
"pinCode": "123456",
"state": "teststate"
},
"childId": "55b009ab4f48f6da3a135bcc",
"studentName": "Testname",
"email": "testmail",
"parentName": "testname",
"phoneNumber": "123456789"
},
{
"address": {
"city": "testcity",
"country": "testcountry",
"houseNumber": "10",
"pinCode": "123456",
"state": "teststate"
},
"childId": "55b3e2114f482e535a109366",
"studentName": "Testname",
"email": "testmail",
"parentName": "testname",
"phoneNumber": "123456789"
}
]
}
}
The output I am getting is:
{
"allStudentAssigned": [
{
"address": {
"city": "testcity",
"country": "testcountry",
"houseNumber": "10",
"pinCode": "123456",
"state": "teststate"
},
"childId": "55b009ab4f48f6da3a135bcc",
"studentName": "Testname",
"email": "testmail",
"parentName": "testname",
"phoneNumber": "123456789"
},
{
"address": {
"city": "testcity",
"country": "testcountry",
"houseNumber": "10",
"pinCode": "123456",
"state": "teststate"
},
"childId": "55b3e2114f482e535a109366",
"studentName": "Testname",
"email": "testmail",
"parentName": "testname",
"phoneNumber": "123456789"
}
]
}