Не удалось десериализовать объект. Не удалось преобразовать значение типа com.google.cloud.Timestamp в строку (найдено вJAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 Не удалось десериализовать объект. Не удалось преобразовать значение типа com.google.cloud.Timestamp в строку (найдено в

Сообщение Anonymous »


I'm trying to read data from a Firestore database. one of which is a Timestamp value. So I have a function to convert into a string. the conversion works for other Timestamps but not this one particularly. I don't know why.

The entire error is this:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.RuntimeException: Could not deserialize object. Failed to convert value of type com.google.cloud.Timestamp to String (found in field 'expiryDate')] with root cause

Here is the model

@Data @NoArgsConstructor @AllArgsConstructor public class Jobs { @DocumentId private @Nullable String jobId; private String title; private List applications; private String company; private String description; private String location; private String requirements; private String views; private Timestamp expiryDate; private Timestamp postedAt; public void setExpiryDate(String expiryDate) throws ParseException { this.expiryDate = Timestamp.fromProto(Timestamps.parse(expiryDate)); } public void setPostedAt(String postedAt) throws ParseException { this.postedAt = Timestamp.fromProto(Timestamps.parse(postedAt)); } } Here is the controller

@RestController @RequestMapping("/api/jobs") @Tag(name="Jobs", description = "Retrieves info related to jobs") public class JobsController { // http://localhost:8080/api/jobs @Autowired private JobsService jobsService; public JobsController(JobsService jobsService) { this.jobsService = jobsService; } @Operation(summary = "Get a list of all Jobs", method = "GET") @ApiResponses(value = { @ApiResponse( responseCode = "200", description = "Jobs Found"), @ApiResponse(responseCode = "500", description = "unable to retrieve Jobs", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ApiResponseFormat.class))) }) @GetMapping("/") // http://localhost:8080/api/jobs/ public ResponseEntity getAllJobs() { try { List jobList = jobsService.getAllJobs(); if(!jobList.isEmpty()) return ResponseEntity.ok(new ApiResponseFormat(true,"Jobs retrieved successfully", jobList, "500")); else return ResponseEntity.status(HttpStatus.NO_CONTENT) .body(new ApiResponseFormat(true,null,null,null)); } catch (ExecutionException | InterruptedException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body(new ApiResponseFormat(false, "Error retrieving Jobs", null, e.getMessage())); } } Here is the the Service:

@Service public class JobsService { private Firestore firestore; public JobsService(){ this.firestore = FirestoreClient.getFirestore(); } public Jobs documentSnapshotToJobs(DocumentSnapshot document) { if (document.exists()) { return document.toObject(Jobs.class); } return null; } public List getAllJobs() throws ExecutionException, InterruptedException { CollectionReference jobsCollection = firestore.collection("Jobs"); ApiFuture future = jobsCollection.get(); List jobsList = new ArrayList(); for (DocumentSnapshot document : future.get().getDocuments()) { Jobs jobs = documentSnapshotToJobs(document); if (jobs != null) { jobsList.add(jobs); } } return jobsList; } I'm using Postman to alter the database, When I try to do a GET request it is supposed to return a list of all of the jobs. But I'm getting nothing. the URL is correct because I am getting the error messages.

Firestore Database screenshot

stack trace


Источник: https://stackoverflow.com/questions/780 ... le-cloud-t
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»