Hey guys I'm trying to save the following class to my collection on Firebase.
public class Review {
private String username;
private String comment;
private int grade;
private String gender;
private LocalDateTime timestamp;
}
However when I use Postman to send the request, I get the following error:
2021-12-19 23:53:01.652 ERROR 3348 --- [nio-9999-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make private java.time.chrono.IsoChronology() accessible: module java.base does not "opens java.time.chrono" to unnamed module @4e268090] with root cause
java.lang.reflect.InaccessibleObjectException: Unable to make private java.time.chrono.IsoChronology() accessible: module java.base does not "opens java.time.chrono" to unnamed module @4e268090
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) ~[na:na]
at java.base/java.lang.reflect.Constructor.checkCanSetAccessible(Constructor.java:188) ~[na:na]
at java.base/java.lang.reflect.Constructor.setAccessible(Constructor.java:181) ~[na:na]
at com.google.cloud.firestore.CustomClassMapper$BeanMapper.<init>(CustomClassMapper.java:635) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.loadOrCreateBeanMapperForClass(CustomClassMapper.java:382) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.serialize(CustomClassMapper.java:180) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.access$500(CustomClassMapper.java:53) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper$BeanMapper.serialize(CustomClassMapper.java:941) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.serialize(CustomClassMapper.java:181) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.access$500(CustomClassMapper.java:53) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper$BeanMapper.serialize(CustomClassMapper.java:941) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.serialize(CustomClassMapper.java:181) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.serialize(CustomClassMapper.java:153) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.access$500(CustomClassMapper.java:53) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper$BeanMapper.serialize(CustomClassMapper.java:941) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.serialize(CustomClassMapper.java:181) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.serialize(CustomClassMapper.java:104) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.CustomClassMapper.convertToPlainJavaTypes(CustomClassMapper.java:79) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.UpdateBuilder.set(UpdateBuilder.java:213) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.UpdateBuilder.set(UpdateBuilder.java:195) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at com.google.cloud.firestore.DocumentReference.set(DocumentReference.java:205) ~[google-cloud-firestore-1.35.0.jar:1.35.0]
at dians_project.mapedonija.service.ShopService.updateShop(ShopService.java:76) ~[classes/:na]
at dians_project.mapedonija.service.ShopService.addReviews(ShopService.java:115) ~[classes/:na]
at dians_project.mapedonija.controller.ShopController.addShopReview(ShopController.java:70) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.12.jar:5.3.12]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067) ~[spring-webmvc-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.12.jar:5.3.12]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.12.jar:5.3.12]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:681) ~[tomcat-embed-core-9.0.54.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.12.jar:5.3.12]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.54.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.54.jar:9.0.54]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.12.jar:5.3.12]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.12.jar:5.3.12]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.12.jar:5.3.12]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.12.jar:5.3.12]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.12.jar:5.3.12]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.12.jar:5.3.12]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.54.jar:9.0.54]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
It's invoked when I call the following method (to set the document in Firestore):
dbFirestore.collection("shops").document(shop.getId()).set(shop);
I have a list of Review
for every Shop
so after adding a new Review
I update the same Shop
.
My guess is that there's a problem with Firestore processing the LocalDateTime
variable. Any solutions to this error or an alternative way of storing a timestamp in Firestore?
CodePudding user response:
I’m not sure if this is the root of your problem, but it may be.
LocalDateTime
is not a timestamp
LocalDateTime
is exactly the wrong data type for a timestamp. That class represents a date with time-of-day but lacks the context of a time zone or offset from UTC.
For a moment as seen in UTC, use Instant
.
For a moment as seen in a time zone, use ZonedDateTime
.
For a moment as seen with an offset from UTC, use OffsetDateTime
.
To communicate a moment with a SQL-oriented database, use OffsetDateTime
.
This has been covered many times on Stack Overflow, so search to learn more.