java.util.ArrayList cannot be cast to com.vaadin.flow.function.SerializableSupplier. This happens if I pass a parameter to a service function and cast It to SerializableSupplier eg. SerializableSupplier<List<? extends Results>>
Can you please show the code?
Repository
List findByPatientTransferOrderByElementsOrderAsc(PatientTransfer patientTransfer);
Service
public SerializableSupplier<List<? extends LaboratoryResults>> serializablefindByPatientTransferOrderByElementsOrderAsc(PatientTransfer patientTransfer){
return (SerializableSupplier<List<? extends LaboratoryResults>>) laboratoryResultsRepository.findByPatientTransferOrderByElementsOrderAsc(patientTransfer);
}
View Using ReportUI
StreamResource pdf = report1.getStreamResource(“laboratory.pdf”, laboratoryResultsService.serializablefindByPatientTransferOrderByElementsOrderAsc(patientTransfer), PrintPreviewReport.Format.PDF);
What should this code do? This looks totally obscure
And how do you expect a list to be casted to a Supplier? You can use () → list instead
It should print results filtered using the patientTransfer in PDF format. It works well if you use laboratoryResultsService::findAll i.e with no filters in the service function
You can use () → list instead, do have a small sample
But what is SerializableSupplier?
That’s just a Vaadin interface which extends Supplier with Serializable
That is the whole example
In that case this will never work:
return (SerializableSupplier<List<? extends LaboratoryResults>>)
Because the repository returns a list
You cannot cast something into something else
How do you return to a SerializableSupplier, maybe a link with more information could guide me well too not to make errors
Replace the code Simon posted with “return () ->”
Okay. Thank you
Thanks knoobie , it worked with new SerializableSupplier function as you guided.