1

I am still a newbie with Spring Data Rest and I'm having some issues with it while I have to parse a LocalDate value to an endpoint. I have searched info's in other topics too but I'm still stucked, this is the problem: I have one Entity with this code .

@Entity
@Table(name="calendario_parcheggio")
@Setter
@Getter
public class CalendarioParcheggio {


    @Id
    @Column(name="data_parcheggio")
    @DateTimeFormat(iso = DateTimeFormat.ISO.DATE )
    @JsonFormat(pattern="yyyy-MM-dd")
    private LocalDate data;

    @Column(columnDefinition = "ENUM('ATTIVO', 'ARCHIVIATO')")
    @Enumerated(EnumType.STRING)
    private Stato stato;
    
    @OneToMany(cascade=CascadeType.ALL)
    @JoinColumn(name="data_parcheggio")
    private List<Parcheggio> parcheggio;

    public enum Stato {
            ATTIVO,
            ARCHIVIATO,
     }
}

It's an Entity linking the Date and its status for a Parking that works hourly.Matching this table on MySQL

CREATE TABLE calendario_parcheggio (
   data_parcheggio DATE PRIMARY KEY,
   stato ENUM ('ATTIVO','ARCHIVIATO') NOT NULL DEFAULT ('ATTIVO')
); 

When I start the server everything is ok , but when i try (by browser or Postman) to check the data of a particular instance (in my case : "http://localhost:8080/parkingsystem/api/calendario-parcheggio/2022-10-18") ,I get this problem :

{"cause":    
     {"cause":      
        {"cause": null,      
        "message": "Text '2022-10-18' could not be parsed at index 2"     
        },
      "message": "Parse attempt failed for value [2022-10-18]"  
     },   
    "message": "Failed to convert from type [java.lang.String] to type [java.time.LocalDate] for value '2022-10-18'; 
    nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2022-10-18]"
} 

And this is the Repository

@RepositoryRestResource(collectionResourceRel="calendarioParcheggio", path="calendario-parcheggio")
public interface CalendarioParcheggioRepository extends JpaRepository<CalendarioParcheggio, LocalDate> {
}

Can you help me to find the solution please?I hope I have explained the problem well enough, my English is still in training :)

SimoneP21
  • 11
  • 1

0 Answers0