Mar 14th, 2012, 11:22 AM
Working with Entities...or not?
I am working on an application based on SOA using REST based services. The UI calls a REST based service passing it a JSON or receiving a JSON. The UI and service layers are implemented using different technologies, but can both speak "REST". We plan on using MongoDB in the backend (services layer) which is written in Java.
My question, is... in the services layer, since I can save a doc (json) to Mongo and I need to send a json to the UI, should I convert the json to entity? or should I deal with json directly. Since I can query the json and work with json, by converting to an entity am I not tying myself to changing my entities everytime the requiremnts change? If I deal with json, I am not restricted.
I know working with entities is easier and I have always done that in a relational model. But with UI and services communication happening via JSON and Mongo taking in (saving/querying etc) JSON directly, should I just work with JSON?
Thank you for your suggestions/opinions
Mar 14th, 2012, 03:20 PM
Personally, I would just save the JSON. If it is just a pass through from the UI down to the DB why do extra work if you don't need to.
On the other hand, if you have to do a lot of manipulation to the json in your code and you don't have a simple API to work with it in code, then in those use cases it might be easier to use Jackson to convert your json to domain objects.
Mar 14th, 2012, 05:30 PM
I agree and I have a mix of both...so,
Using spring-data how can I write JSON directly to Mongo, without a mapping or conversion step. Do I have to write a custom converter?...thanks
Mar 14th, 2012, 06:12 PM
What about using the Template class? You should be able to just pass in the JSON String to it to save to the db.
I am also curious if you can create a Repository with <String> and if that would work. But definitely through the Template. You document is the JSON String.
Mar 15th, 2012, 11:02 AM
ok, will give it a shot and post back here
Tags for this Thread