Я пытался позвонить REST ( Студент, микро-сервис курса) из моей регистрации микро-услуги для вставка новой регистрации, но всякий раз, когда я звоню в эти службы Студент Микро-служба показывает следующее ошибка .
> org.springframework.web.client.RestClientException: Error while extracting response for type [class com.homeexam.registrationmanagementserver.model.Student] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `com.homeexam.registrationmanagementserver.model.Student` out of START_ARRAY token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `com.homeexam.registrationmanagementserver.model.Student` out of START_ARRAY token
at [Source: (PushbackInputStream); line: 1, column: 1]
Я старался изо всех сил, чтобы решить проблему поиска в Google, но я не могу найти какое-либо соответствующее решение относительно этой проблемы.Помоги мне!
Это мой класс RegistrationService , где я вызываю эти микроуслуги:
public Registration create(Registration registration) {
Student student = restTemplate.getForObject(studentsUrl, Student.class);
Section section = restTemplate.getForObject(sectionsUrl, Section.class);
Course course = restTemplate.getForObject(coursesUrl, Course.class);
/*registration = new Registration(registration.getId(), student.getId(),student.getProgram(),
section.getSectionNumber(),course.getCourseCode(),section.getFacultyInitial());*/
registration.setId(registration.getId());
registration.setStudentId(student.getId());
registration.setProgramName(student.getProgram());
registration.setCourseCode(course.getCourseCode());
registration.setFacultyInitial(section.getFacultyInitial());
registration.setSectionNumber(section.getSectionNumber());
Optional<Registration> optionalReg = registrationRepository.findById(registration.getId());
Optional<Registration> byCourseCode = registrationRepository.findById(Integer.valueOf(registration.getCourseCode()));
if (optionalReg.isPresent() ) {
throw new ResourceAlreadyExistsException();
} else if (byCourseCode.isPresent())
throw new AlreadyRegisteredException();
else {
return registrationRepository.save(registration);
}
}
Но код работает без вызова службы Micro, связанной сinfo.
Регистрация JSON
{
"courseCode": "string",
"facultyInitial": "string",
"id": 0,
"programName": "string",
"sectionNumber": 0,
"studentId": "string"
}
Студент JSON
{
"id": "201600000001",
"name": "UML Diagram",
"email": "uml@gmail.com",
"address": "Texas,USA",
"dob": "1998-09-11",
"mobileNumber": "01110000000",
"dateOfAdmission": "2018-09-10",
"program": "BSc. in EEE",
"role": "Student",
"password": "1555"
}
Курс JSON
[
{
"courseCode": "CS193",
"courseTitle": "Android Application",
"courseCredit": 3,
"sectionList": [
{
"id": 1,
"sectionNumber": 1,
"seatLimit": 25,
"semesterNumber": 11,
"facultyInitial": "ATA",
"course": {
"courseCode": "CS193",
"courseTitle": "Android Application",
"courseCredit": 3,
"sectionList": null,
"gradeList": null
}
},
{
"id": 2,
"sectionNumber": 2,
"seatLimit": 30,
"semesterNumber": 11,
"facultyInitial": "ABA",
"course": {
"courseCode": "CS193",
"courseTitle": "Android Application",
"courseCredit": 3,
"sectionList": null,
"gradeList": null
}
}
],
"gradeList": null
}
]
Раздел JSON
[
{
"id": 1,
"sectionNumber": 1,
"seatLimit": 25,
"semesterNumber": 11,
"facultyInitial": "ATA",
"course": {
"courseCode": "CS193",
"courseTitle": "Android Application",
"courseCredit": 3,
"sectionList": null,
"gradeList": null
}
},
{
"id": 2,
"sectionNumber": 2,
"seatLimit": 30,
"semesterNumber": 11,
"facultyInitial": "ABA",
"course": {
"courseCode": "CS193",
"courseTitle": "Android Application",
"courseCredit": 3,
"sectionList": null,
"gradeList": null
}
}
]
Student.java
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(of = {"id","name"})
@Document
public class Student {
@Id
private String id;
private String name;
private String email;
private String address;
private LocalDate dob;
private String mobileNumber;
private LocalDate dateOfAdmission;
private String program;
private Role role;
private String password;
}
Registration.java
public class Registration {
@Id
private int id;
private String studentId;
private String programName;
private int sectionNumber;
private String courseCode;
private String facultyInitial;
}