Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39928
| Path | csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java record |
| Date | Wed, 8 Mar 2023 21:44:10 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 28 |
| Message-ID | <tuas2m$12sbr$1@dont-email.me> (permalink) |
| References | <906f5a76-929d-46cb-b5e0-fcc8e4ad4e0en@googlegroups.com> <tuanur$125a7$1@dont-email.me> <c9a3f6c1-be79-4d17-898a-fb1b3c5eb77dn@googlegroups.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Wed, 8 Mar 2023 20:44:06 -0000 (UTC) |
| Injection-Info | reader01.eternal-september.org; posting-host="b4473d385aef394a9d80fd7b7ee6353b"; logging-data="1143163"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/g/cnbB9b3QXptb7PA+IC" |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 |
| Cancel-Lock | sha1:SYHLA1qicGaOyTozNMh5abs/EZ8= |
| In-Reply-To | <c9a3f6c1-be79-4d17-898a-fb1b3c5eb77dn@googlegroups.com> |
| Content-Language | en-US |
| Xref | csiph.com comp.lang.java.programmer:39928 |
Show key headers only | View raw
On 08/03/2023 21:14, 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. I doubt it's going to be much different than Lombok in terms of performance or reliability. The only difference I can see is in terms of clarity of intent. If you start your class with `record`, then you make clear for all to see what you intend the class for. The heuristic value of that is non-zero. I haven't had the chance to use records in production yet, so I can but mostly speculate. A quick lookup however suggests that you can use Lombok's @Builder on `record` classes. -- DF.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-01 11:18 -0800
Re: Java record Arne Vajhøj <arne@vajhoej.dk> - 2023-03-01 20:23 -0500
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-02 04:01 -0800
Re: Java record Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2023-03-08 20:33 +0100
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-08 12:14 -0800
Re: Java record Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2023-03-08 21:44 +0100
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-08 12:54 -0800
Re: Java record Arne Vajhøj <arne@vajhoej.dk> - 2023-03-13 10:55 -0400
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-13 08:25 -0700
Re: Java record Jason H <DarthPiriteze@deathstar.gal> - 2023-03-21 18:02 +0000
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-22 04:04 -0700
csiph-web