I use vaadin 23. I pass a list of book objects to the client via properties, and when I want to send back a book object by using @ClientCallable getting a type error.
Error:
java.lang.IllegalArgumentException: Class 'com.lib.web.business.book.BookDetailDesign' has the method 'onClickBook' whose parameter 0 refers to unsupported type 'com.lib.web.business.book.entities.Book'
public class Book implements Serializable
{
private static final long serialVersionUID = 1L;
private int idBook;
private String name;
}
public void onBookClicking(Book b)
{
System.out.println("BookID: "+q.getIdBook( ) );
System.out.println("Category: "+q.getCategory( ) );
getUI( ).ifPresent( ui -> ui.navigate( BookDetailDesign.class, URLEncoder.encode( b.getName( ).replace( "?", "%3F" ), StandardCharsets.UTF_8 ) ) );
}
@ClientCallable
doesn't "know" how to deserialize the received JSON into some specific Java object. Only simple primitive values are supported.
If you want to send a complex object, then you can work around that by creating an explicit JSON string in the browser using JSON.stringify(object)
, receiving that as a String
argument to the @ClientCallable
method and using a JSON library such as Jackson configured in an way that is appropriate for your Java types.