Issue: Source DTO and Target DTO structure and property is different
I have an incoming request JSON as
Employee -> Address (addr1, addr2, addr3), Info (Age, Birth, DOB, Gender), Training (tr1, tr2, AppDTO)
AppDTO -> appName, appId, appPrice
I need to call a third party API which accepts the following JSON
Employee -> ad1, ad2, EmpInf (ageinnumber, birthdate, DOB), t1, appName
Question:
I have created two DTOs – EmployeeDTO in request package and EmployeeDTO
in external package. I tried with @JSONIgnore and @JSONProperty in target DTO in
external package but couldn’t achieve it as above seems to be complex. Even tried with DOT . but doesn’t work as expected. Reason (Cannot use both JSONIgnore and JSONProperty at the same time)
Example, mapping t1, appName is more complex
Can someone please kindly share code how to achieve this with code? I’m using BeanConverter to convert
the source to target DTO and trying to achieve via JSONIgnore and @JSONProperty
Please help me on how to achieve using JSONIgnore and JSONProperty and any other alternate solution to resolve this.
Thank you.
Convert Source DTO ==> Target DTO
Java Development is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.