I am currently writing a java REST Web Service using Netbeans and Glassfish.
The WebService is a CRUD web service on an SQL database.
Netbeans did most of the work for me by implementing Simple CRUD methods.
But I still have 1 major concern: What is the best way to pass a complex object (like a date)?
for example: I want to write the function @GET getLessonsByDate(Date start,Date end).
From what I read, I can either use the @Consume annotation, @QueryParam annotation or @PathParam. What is best? what if need two dates? what if I also need another Complex data type?
please help me out…
Web services operate on strings. Ultimately all of your data is going to be formatted as a string, so you’re better off doing the formatting yourself so you get control.
I would format your dates in a standard way, like YYYY-MM-DD HH-MM-SS. As for other data types, it’s really type-dependent, but JSON is often a good choice. The world is slowly moving away from XML as a serialization format toward JSON.