I generated DTOs with JHipster automatically. I didn't know how to see my json just with console and i get null in one to many relationship.
This is what i get.[OperationDTO{id=1, date='2015-08-05T08:48:00Z', description='Mississippi Account Associate', amount=13968.00, bankAccount=BankAccountDTO{id=1, name='monitor', balance=null, user=null}, labels=[]}]
And i am using this repository from github
https://github.com/jhipster/jhipster-sample-app-dto
Thanks.
why in the json i get from jhipster dtos automatic generation give me null one to many relationship?
Asked
Active
Viewed 100 times
0

Troo TrIIs
- 7
- 1
1 Answers
2
This is the intended behaviour: https://www.jhipster.tech/using-dtos/#how-dtos-work-in-jhipster
It will aggregate many-to-one relationships, only using the ID and the field used to display it in your client-side framework
I had the same questions at first. The autogenerated DTOs only provide linking information. Fields which are not the id or display element are left as null. If this is not what you want, you can modify the MapStruct mappers or define your own conversion to and from DTOs.
You can inspect the JSON via the Swagger interface: Login as admin then go to Admin > API (http://localhost:8080/admin/docs).

jelharou
- 86
- 5
-
thanks a lot <3 ? can you please tell me how i can show another element with the id and sorry if i am bothering you – Troo TrIIs Aug 31 '22 at 15:08
-
thanks bro i know how now bro thanks a lot – Troo TrIIs Aug 31 '22 at 15:15
-
I cannot (yet) comment on your other question. Can you include your full JDL file to help us understand the issue. You can try getting everything working without DTOs to confirm that it is indeed a DTO issue. I actually think it is more than a DTO issue: you may need to either modify the code in the Repository so that it fetches the underlying entities in the same query, or explicitly set them (possible in the service). – jelharou Sep 05 '22 at 12:22
-
I actually fixed this problem. I had to add the name of all the fields in the mapping annotation. But can you please answer my other question ? https://stackoverflow.com/questions/73594083/childdto-into-parentdto-in-jhipster-with-mapstruct Thanks in advance – Troo TrIIs Sep 05 '22 at 12:48
-
Yes, my above comment is actually intended for the other question but I can't comment there. If you post your full JDL there we should be able to help. – jelharou Sep 05 '22 at 12:59
-
entity Employee { firstName String lastName String } entity Role { Name String } relationship OneToMany { Employee{role} to Role{employee required} } dto all with mapstruct – Troo TrIIs Sep 05 '22 at 13:18
-
{ "id": 1, "firstName": "John", "lastName": "Doe", "roles": [ { "id": 1 "name": "Admin" }, { "id": 2 "name": "Collector" } ] } – Troo TrIIs Sep 05 '22 at 13:19
-
in my last comment the json i want to get from dtos – Troo TrIIs Sep 05 '22 at 13:20