1

Sometimes i use jsonschema2pojo to convert some json into a java object, but according with these definitions I always be confused if it is a VO or a DTO. Im sure that isnt an entity, but I dont know how to classify it correctly.

The purpose of the use, is just to get a json in an object. After that, i manipulate these data over the app.

Tim
  • 41,901
  • 18
  • 127
  • 145
KpsLok
  • 853
  • 9
  • 23

2 Answers2

0

Technically, it's a DTO until you add additional business logic into the class rather than simply the JSON serialization annotations.

The reason I say so is that it's responsible for both transfer and deserialization of a JSON object

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
0

I would say that a DTO is a POJO that is setup for the exclusive purpose of being transmitted to and from a datasource. So I would say that if you plan on using the POJO just for transmitting to and from a datasource, then I would call it a DTO. That would let me know what its purpose is for. If the POJO is going to be used for other things beyond just transmitting to and from a datasource, than I would call it a POJO.

Typically I do not see these terms used much anymore. Now I just see POJO and they typically go into a package with the name "model" or "domain". If I see these packages in a project, I know these are POJO's that can be used for business logic or transmitting.

Why its probably not a VO: VO's are small objects, like coordinates, or money. They are immutable and do not contain many fields. So not really something with multiple fields that you would require JSONshema2pojo. Though when parsing a large JSON, JSONschema2pojo might create many little classes that fit this definition.

EDIT: This is all subjective. And only providing an opinion here.

Jose Martinez
  • 11,452
  • 7
  • 53
  • 68
  • *This is all subjective* - a good reason not to answer and instead close the question as opinion based – Tim Apr 09 '18 at 13:55
  • Thank you for your reply! The additional information about where it is localizated inside the project was a good point for me. Tipically, these kind of class are designed to be into a package called "models", but is it necessary to stay inside a "models.dto" or "models.vo"? – KpsLok Apr 09 '18 at 13:56
  • 1
    @BrennoLeal nothing is necessary, nor does it matter what you name your package. It is all a matter of preference – Tim Apr 09 '18 at 13:58
  • @BrennoLeal not necessary. ultimately packages need to be broken down into smaller packages if there are way too many files in there and it becomes a pain point to look at it. Then it up to your discretion how you want to break down the packages into smaller packages.. – Jose Martinez Apr 09 '18 at 14:18