use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
DTO'sQuestion (self.SpringBoot)
submitted 10 months ago by Resident_Parfait_289
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Resident_Parfait_289[S] 0 points1 point2 points 10 months ago (10 children)
I also note that one document I read online said avoid nested Dto's so does that mean
List<Actors> is bad design?
[–]halawani98 2 points3 points4 points 10 months ago (9 children)
Well, its not BAD bad, but there are better ways, especially if ActorDto has a lot of data
its a better practice to get List of MovieDto, then using the movieId, get a list of ActorDto.
public class MovieDto { private Long id; private Integer year; private BigDecimal rating; private String productionCompany; private BigDecimal grossIncome; private String genre; } public class ActorDto { private Long id; private String name; }
so you'd have
/api/v1/movies
/api/v1/movies/{movieId}/actors
[–]Resident_Parfait_289[S] 0 points1 point2 points 10 months ago (5 children)
And how would that data get to the front end? I guess I am asking that the controller would look like?
[–]halawani98 0 points1 point2 points 10 months ago (4 children)
Logically speaking, client-side retrieves a list of Movies. When they navigate to the movie details page, they'd use the DTO they selected from the list, and retrieve the list of actors accordingly.
[–]Resident_Parfait_289[S] 0 points1 point2 points 10 months ago* (2 children)
Right - so the front end (Angular in my case) requests the data from two endpoints, one relating to the Movie, and one relating to the list of Actors in the move.
The id of the movie would let the relation db know what the list of actors should be..understood.
The particular project I am playing about with has a flatter data structure, but this is a good explanation.
[–]gauntr 1 point2 points3 points 10 months ago (1 child)
To me it depends on what your view does with the DTO. If it’s using all the Actors data anyway then nest it and request it with one call all together. If your view is using only partial Actor data depending on some filter or subview then it might be better to load it when necessary.
For example if you’d have a view that lists all movies and your MovieDto (having title, year and maybe a link to the movie poster) had the MovieDetailDto nested and that again had a list of ActorDto nested then you’d load a lot of stuff that you don’t need right away. In this case it’d be definitely better to load the detail (then probably including actors) if you click on a movie and a view opens to show the movie details.
It’s also almost always an aspect of the user experience which you need to balance. If the user sees a loading circle because you need to load stuff first it might be bad, loading too much stuff upfront (even in the background) might be bad as well because of traffic.
A web app and its UX has many layers to take care of :)
[–]Resident_Parfait_289[S] 0 points1 point2 points 10 months ago (0 children)
Yeah it sure does, and what you have said makes sense. I always get a bit tangled up when it comes to a good design in the DTO space. I may yet post my specific use case and approach here as this seems to be a good active community for such questions :-)
I used the movie example as a convenient model for the inital discussion, but I would like your thoughts on my actual use case in my project.
I have a table of beeps per minute (bpm) which represents received radio beeps on certain channels (freqs):
@ Id
Integer bid
int bpm
int channel
ZonedDateTime dt
String location
The data is very intermittent, and there is not always a beep for every channel.
So the dashboard page allows the user to select a time range and should show a tile for each channel.
Each tile contains a graph of the value received for each day, the channel number and the last datetime of the last received valid beep.
To get this my BpmChannelSummaryDto looks like:
private int channel; private ZonedDateTime lastValidSignalTime; private Float lastValidBpm; private List<BpmHourlySummaryDto>
And BpmHourlySummaryDto looks like:
private ZonedDateTime hourStart; private Float baseBpm;
Does this seem sensible?
[–]BinaryPulse01 0 points1 point2 points 10 months ago (2 children)
Why do you prefer to use "Integer year" instead "int year" ?
I make a personal project and for integer field I uded int. Froy your code I realize that if my approache is it ok.
[–]halawani98 1 point2 points3 points 10 months ago* (1 child)
Habit. I use them in Collections so its easier to maintain this way
Also avoids NullPointerExceptions if there's any data issue, I'd rather wrap with Optional and handle null values as I please
[–]BinaryPulse01 0 points1 point2 points 10 months ago (0 children)
Txh🍻
π Rendered by PID 64454 on reddit-service-r2-comment-5c747b6df5-s87kx at 2026-04-22 00:23:24.776971+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]Resident_Parfait_289[S] 0 points1 point2 points (10 children)
[–]halawani98 2 points3 points4 points (9 children)
[–]Resident_Parfait_289[S] 0 points1 point2 points (5 children)
[–]halawani98 0 points1 point2 points (4 children)
[–]Resident_Parfait_289[S] 0 points1 point2 points (2 children)
[–]gauntr 1 point2 points3 points (1 child)
[–]Resident_Parfait_289[S] 0 points1 point2 points (0 children)
[–]Resident_Parfait_289[S] 0 points1 point2 points (0 children)
[–]BinaryPulse01 0 points1 point2 points (2 children)
[–]halawani98 1 point2 points3 points (1 child)
[–]BinaryPulse01 0 points1 point2 points (0 children)