I have a problem about showing timestamp as a Date in Spring boot.
I always get timestamp as an int value shown below.
"timestamp": 1646735268046
How can I get it as a Date?
Here is my ApiError entity shown below.
@Data
@AllArgsConstructor
public class ApiError implements Serializable {
private int statusCode;
private HttpStatus status;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss'Z'", timezone = "GMT")
private LocalDateTime timestamp;
private String message;
List<String> errorDetails;
}
Here is a function defined in Global Exception Handling class shown below.
@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<Object> handleRefreshTokenException(RefreshTokenException ex) {
List<String> details = new ArrayList<String>();
details.add(ex.getMessage());
ApiError err = new ApiError(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST, LocalDateTime.now() ,
"User Not Found", details);
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(err);
}
Edited:
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime timestamp;
I still get int value.