I am developing a web application which has a typical layered architecture:
a DAO layer that retrieves domain model objects from a database;
this layer communicates with the service layer which does some business operations using those objects;
the web layer (Spring Controllers) use the service layer to retrieve the domain model objects (or collections for them) and pass them to the view layer;
the view layer is either simple JSPs which show the data using JSTL, or JSPs which retrieve some of the data through AJAX in the form of JSON objects (domain objects converted to JSON through Jackson library).
I have been researching about the following:
Very often I need to convert the db fields to a different format to show to the user. For example, a Date might be store as a Timestamp and I want it to show it as a formatted date (e.g. dd/mm/yyyy).
Also, I need to do the opposite, convert some value (usually user input) to the format of a domain model object's property.
My question is, where should I be doing this kind of conversions? Especially with JSON data, they should be already formatted on the AJAX response, I dont think I should format it with Javascript, am I right?
Thank you in advance.