Title: How to construct REST dto's?
Tags: java;json;rest
Question: I am in the process of building a REST api which accepts a set of arguments, processes it and gives a boolean response.
My question is how do I build a dto object. I can create a Java POJO in one of the applications and use it as REST parameter but that creates a dependency on this application.
Is there a better way to pass an object as REST parameter?
note: the reason I am not using path params because my dto object might contain a list of objects as well and I am not sure how to pass that using path param.
Comment: I think I am little confused about this. Please help me out here.
I have seen that sometimes the method catering a REST has a dto object as a parameter, and I was assuming this is another way of passing a param  other than in the message body itself.

Comment: I have the same problem/boubt. Should I use POJO's for my DTO classes or should I use types and add the project despendencies?
Have you found anything @sweetcode ?

Comment: Which language are you using?

Comment: Erm, What do you mean by "Path parameter"? You don't "pass objects" through the URL. You pass them through the message body. So when you do a POST/PUT The Object that you create/object is in the message body. When you do a GET/DELETE the object that was retrieved and/or deleted can be returned in the same fashion.


Here is another answer: You can create a library which contains the DTO class if dependency is your concern.
After all the DTO is dependent on the REST API. If one changes the other must change too.
Comment for this answer: My concern is on the client side also I will need to have this dto class available and which creates a dependency for client class as well.
Comment for this answer: You always will have some kind of dependancy if two applications have to communicate (even if it is only the REST api itself in your case). But if you are not using one class for both you will end up in some kind of code duplication. What exactly is the problem with the dependancy?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2014:00:06/15/14', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><json><rest>', 'Title': "How to construct REST dto's?", 'ViewCount': 691, 'id': 24228675, 'user_AboutMe': '', 'user_AccountId': 2311996.0, 'user_DisplayName': 'sweetcode', 'user_Reputation': 159.0, 'user_Views': 35.0, 'user_id': 2029927.0}}