I am developing an server application that will receive lists of book details from a number of different types of clients. The lists of book details is generated entirely on the client side.
An example list would be as follows:
/*
+-----+----------------+--------------------+-------------+
|Isbn | Author | title |notes |
+-----+----------------+--------------------+-------------+
|02-1 | Stephen King |Cojo |blah blah |
+-----+----------------+--------------------+-------------+
|05-3 | JK Rowlings |Harry Potter |rubbish |
+-----+----------------+--------------------+-------------+
|09-5 | Sun Tzu |The Art of War. |Interesting |
+-----+----------------+--------------------+-------------+
*/
public interface Book { }
public interface ReadingListAPI {
List<Book> save(Book... books);
}
public class ReadingListAPIImpl implements ReadingListAPI {
@POST
@Override
List<Book> save(Book... books) {
}
}
Is it possible to expose the ‘ReadingListAPIImpl.save‘ method to the client via JAX-RS? What format would the client need to use for sending the data.
I’ve done some research on this and believe client could send the data in XML format and the server could use JAXB to unmarshal the data. However this seems quite complex and I’m not sure it would support recieving a list of User defined types.
Are there any other simpler methods like using JSON be for example?
Varargs is actually an array in disguise. So I presume it will be exposed as a collection of elements. If it doesn’t, you can replace it with
List<Book>– you will be iterating it anyway.