Search code examples
javajhipsterdto

why in the json i get from jhipster dtos automatic generation give me null one to many relationship?


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.


Solution

  • 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).