On 3/8/2023 3:14 PM,
e.d.pro...@gmail.com wrote:
>>> In web, we use DTOs on the back end to pass data to and from the
>>> Javascript/Typescript on the front end. It looks like passing to
>>> the front end works, now how do we use it as a model to get the
>>> user input?
>> Note: if you do get an exception, you should at least state its
>> message in your post.
>>
>> According to the changelog, support for Java records has been added
>> to Gson in version 2.10:
>> <
https://github.com/google/gson/releases?q=2.10&expanded=true>.
>> Switch to that and you should be good to go.
>
> Aha! So my sample code does work. I hadn't updated my dependencies in
> a while on my test project. I need to finish that pom and add a site
> report with the dependency-updates plugin. I was referencing gson
> 2.8.6. I switched to 2.10.1 and it solved that error. Now, if we can
> switch to Java 17 (15+), we use record for all DTOs? This is much
> more efficient and/or secure than using classes with lombok?
>
> All fields in a record are final, so it can only have the one
> constructor with parameters for every field? This sounds tedious to
> instantiate on the back end unless you're using a framework or
> convenience method that's going to populate, from a ResultSet? Front
> end data is simple if you can instantiate from JSON using gson.
> Requiring all values final on instantiation will require a very
> different DTO structure than the legacy apps I've seen.
Getters and setters has been considered too verbose
for a couple of decades.
Some just use their IDE to generate them.
The Lombok thing was invented to autogenerate the
trivial code.
Scala and Kotlin has case class and data class
respectively to do it simpler.
Java after many years got the record thing.
If you can live with the immutable aspect
(which is sort of in fashion today), then
it would make sense to use them for all
sorts of data classes.
Arne