I'm facing some difficulties while trying to convert JSON response which contains properties with under_score, to DTO with lowerCamelCase properties.
JSON for example:
{
"promoted_by": "",
"parent": "",
"caused_by": "jenkins",
"watch_list": "prod",
"u_automation": "deep",
"upon_reject": "cancel"
}
DTO for example:
@Data
public class TicketDTO {
private String promotedBy;
private String parent;
private String causedBy;
private String watchList;
private String uAutomation;
private String uponReject;
}
Mapper:
@Mapper(componentModel = "spring")
public interface ITicketMapper {
default TicketDTO toDTO(JsonObject ticket) {
Gson gson = new GsonBuilder()
.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
.create();
return gson.fromJson(incident, TicketDTO.class);
}
}
This example is not working of course, I would like to know if it's possible to do this conversion with Gson.
Appriciate your help.