2

Consider a restful service in Spring MVC. I am wondering how to package my response classes, i.e. how to name the containing package.

First I thought of them as being domain objects. But they are actually a bit different, because they wrap my true domain objects like this:

{
    header: {
        // ...
    },
    domainObjectSpecificKey: {
        // domain object properties
    }
}

The response class is mapped to the top-level JSON object. So then I thought they may be DTOs actually -- but as far as I understand DTOs are used between application layers, and not for "output" objects to be used between separate applications.

So my questions is: does this kind of object have a special name? If yes, what's that? If not, can we definitely state that it is NOT a DTO or a domain object, i.e. should I name the package differently or can I use the one of that seems better to my liking?

  • What is the consumer if not another part of the application? If you consider it like that, it's easy to think of these kinds of objects as DTO's – Andy Hunt May 26 '15 at 9:24
  • It is some other application. A totally different project. In fact, there can be a couple of other apps using this restful service, they are not "one big application". – dsplynm May 26 '15 at 9:26
  • Even then, the name "data transfer object" describes its purpose: transferring data (out of your system) – Andy Hunt May 26 '15 at 9:35
  • @AndyBursh, since no-one else seems to be posting other oppinions, if you post your comment as an answer, I'll accept it. Thank you for your thoughts! – dsplynm May 26 '15 at 11:19
  • Why don't you simply name your package "response classes?" The correct name is the one that is most descriptive to you, and you're calling them response classes. – Robert Harvey May 26 '15 at 15:25
1

I would consider a class representing a JSON response to be a Data Contract. Keeping it separate from your DTOs and Domain Objects also keeps the clients consuming your service decoupled from the rest of your system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.