0

We are using mapstruct in our project . While it works awesum for a dto to a domain object (say EmployeeDTO to EmployeeData with similiar properties) - we have a need to process an incoming json string . We are trying to write a very generic mapper that maps from the incoming json string to a java object.

So lets say we have EmployeeDTO like this

{ id: 1,name="xxx"} but its coming as a string and i have a mapstruct mapper thusly

@Mapper
EmployerMapper()
{
   EmployeeData toEmployeeFromJsonString( String empString} ;// where empString is a jsonString
}

its not working properly and i am not getting the appropriate object created with the right property from the json String( I also tried with jsonobject as well but that doesn't work either)

The reason why we cant have specific DTOs is because we want to have a loose coupling between the Employee microservice and the rest of the microservices ( there are a handful ) mapstruct is not creating the appropriate getters and setters and there could be more properties in the DTO that we dont care in this microservice. 1. Is there support for json objects in mapstruct directly? 2. If i enhance it with GSON support how can i integrate it with mapstruct so that i have only one way of mapping in my product.

user1540821
  • 41
  • 1
  • 6

1 Answers1

0
  1. No. MapStruct is a mapping framework, not a parsing framework
  2. For deserialising JSON you have few specific frameworks: checkout How to parse JSON in Java
Sjaak
  • 3,602
  • 17
  • 29