Problem with variables Date in Spring Boot - Angular 6


When dealing with data of type Date I am having problems. On the server ( Spring Boot ) I am collecting a Date field from MySQL , and this information is correct in the Spring Boot Model when debugging. But if I see that call on the outside, the JSON generated has this field as TimeStamp . I guess the main error is this, but if later in Angular I try to parse this variable to Date and do a typeof, it returns that the variable is Object .

Any ideas? I leave the code below:



@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Patient {

private Long id;

private String gender;

private Date birthdate;

public Long getId() {
    return id;

public void setId(Long id) { = id;

public String getGender() {
    return gender;

public void setGender(String gender) {
    this.gender = gender;

public Date getBirthdate() {
    return birthdate;

public void setBirthdate(Date birthdate) {
    this.birthdate = birthdate;

Controller Code:

 * Obtenemos el modelo Patient a partir de su Id
 * @param id
 * @return
public ResponseEntity<?> getPatient(@PathVariable("id") Long id) {

    logger.debug("Llamada al método getPatient()");

    Patient patient = patientService.getPatient(id);

    if(patient == null) {
        logger.error("No se ha encontrado al usuario " + id);
        return new ResponseEntity(HttpStatus.NOT_FOUND);

    return new ResponseEntity<Patient>(patient, HttpStatus.OK);

Service Code: (getOne method of JpaRepository)

public Patient getPatient(Long id) {
    return patientDao.getOne(id);





public getAllPatients() {
return this.http.get<Patient[]>(this._baseURL + '/all');


export class Patient {

id: number;
gender: string;
birthdate: Date;

constructor() { }
asked by Carlos Devesa 23.11.2018 в 21:13

1 answer


With respect to typeof the documentation says:


The typeof operator returns a string indicating the type of the operand   without evaluating it.

Of which you can return:

  • function
  • string
  • number
  • object
  • undefined
  • boolean
  • So it's normal for you to return as output 'object' .

    On the other hand, if you want to receive the formatted field as a date, you can add the following to your file:


    Or in its respective format if you use a application.yml .

    With this you achieve that the result is of the following form:

        "id": 1,
        "gender": "X",
        "birthdate": "2018-11-23"

    In version 2.1.0 of Spring Boot this parameter already comes by default to true in which case the result is shown in the following way:

        "id": 1,
        "gender": "X",
        "birthdate": "2018-11-24T02:32:09.673+0000"

    Whose formats you can now work with javascript , for example:

    new Date("2018-11-24T02:32:09.673+0000")
    Fri Nov 23 2018 20:32:09 GMT-0600 (hora estándar central)
    new Date("2018-11-23")
    Thu Nov 22 2018 18:00:00 GMT-0600 (hora estándar central)


  • typeof
  • answered by 24.11.2018 в 03:38