У меня есть два класса Document, как показано ниже. Однако при запросе документа запроса пользовательский документ продолжает возвращать нуль.
Документ запроса
@NoArgsConstructor
@Document(collection = "request")
public class Request {
@Getter
@MongoId
private String id;
@Getter
@Setter
private String description;
@Getter
@Setter
private Equipment equipment;
@Getter
@Setter
private LocalDateTime localDateTime;
@DBRef(db = "user")
@Getter
@Setter
private User requestedBy;
public Request(String description, Equipment equipment, LocalDateTime localDateTime, User requestedBy) {
this.description = description;
this.equipment = equipment;
this.requestedBy = requestedBy;
this.localDateTime = localDateTime;
}
}
** Документ пользователя **
@NoArgsConstructor
@Document(collection = "user")
public class User {
@Getter
@MongoId
private String id;
@Getter
private LocalDateTime localDateTime = LocalDateTime.now();
@Getter
@Setter
private String firstName;
@Getter
@Setter
private String lastName;
@Getter
@Setter
@Indexed(unique = true)
private String email;
@Getter
@Setter
private String password;
@Getter
@Setter
private boolean isActive;
@Getter
@Setter
private Role role;
public User(String firstName, String lastName, String email, String password, boolean isActive, Role role) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.password = password;
this.isActive = isActive;
this.role = role;
}
}
Что я делаю не так? Пожалуйста, найдите ошибку ниже:
2020-04-07 18: 03: 50.308 ОШИБКА 21051 --- [nio-8080-exe c -2] oa c. c. C. [. [. [/]. [dispatcherServlet]: Servlet.service () для сервлета [dispatcherServlet] в контексте с путем [] вызвала исключение [Ошибка обработки запроса; вложенное исключение: java .lang.NullPointerException] с root причиной
java .lang.NullPointerException: null at uk.a c .gcu.server.services.UserService.mapToUserModel (UserService . java: 37) ~ [classes /: na] в Великобритании c .gcu.server.services.RequestService.mapToRResponse (RequestService. java: 55) ~ [classes /: na] в java .base / java .util.stream.ReferencePipeline $ 3 $ 1.accept (ReferencePipeline. java: 195) ~ [na: na] в java .base / java .util.ArrayList $ ArrayListSpliterator.forEachRemaining (ArrayList. java: 1654) ~ [na: na] в java .base / java .util.stream.AbstractPipeline.copyInto (AbstractPipeline. java: 484) ~ [na: na] в java .base / java .util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline. java: 474) ~ [na: na] в java .base / java .util.stream.ReduceOps $ ReduceOp. valuSequential (ReduceOps. java: 913) ~ [na: na] в java .base / java .util.stream.AbstractPipeline.evaluate (AbstractPipeline. java: 234) ~ [na: na] в java .base / java .util.stream.ReferencePipeline.collect ( ReferencePipeline. java: 578) ~ [na: na] at uk.a c .gcu.server.services.RequestService.allRequests (RequestService. java: 51) ~ [classes /: na] в Великобритании. a c .gcu.server.controllers.RequestController.getAllRequests (RequestController. java: 32) ~ [classes /: na] в java .base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (собственный метод) ~ [na: na] в java .base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl. java: 62) ~ [na: na] в java .base / jdk.internal.reflect. DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl. java: 43) ~ [na: na] в java .base / java .lang.reflect.Method.invoke (Метод. java: 566) ~ [na: na ] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke (InvocableHandlerMethod. java: 190) ~ [spring-web-5.2.4.RELEASE.jar: 5.2.4.RELEASE] в org.springframework.we .method.support.InvocableHandlerMethod.invokeForRequest (InvocableHandlerMethod. java: 138) ~ [spring-web-5.2.4.RELEASE.jar: 5.2.4.RELEASE]