I am using a RestResponse class that I writed . I am using this class in each service and also Dto class, but I coulnd't get my dto data correctly. Data is in RestResponse class but it is always responding with LinkedHashMap . Data is coming in LinkedHashMap I need to cast it to my Dto data
ResponseEntity<RestResponse> result;
result = (new RestTemplate()).postForEntity(uri, requestBody, RestResponse.class);
But I need the result as ResponseEntity<RestResponse<SomeDto>>
.
Is there any way to fix this.
When I debug it . Data object seems LinkedHashMap. But in the other service I am using ResponseEntity<RestResponse<SomeDto>>
for response.All classes are same in each service.
This is my RestResponse class:
public class RestResponse<T> {
private T data;
private String titleLanguageKey;
private String title;
private String messageLanguageKey;
private String message;
private ResponseTypeEnum type;
public RestResponse() {}
public RestResponse(T data, ResponseTypeEnum type) {
this.data = data;
this.type = type;
}
public RestResponse(String messageLanguageKey, String message, ResponseTypeEnum type) {
this.title = "";
this.titleLanguageKey = "";
this.message = message;
this.messageLanguageKey = messageLanguageKey;
this.type = type;
}
public RestResponse(String titleLanguageKey, String title, String messageLanguageKey, String message, ResponseTypeEnum type) {
this.title = title;
this.titleLanguageKey = titleLanguageKey;
this.message = message;
this.messageLanguageKey = messageLanguageKey;
this.type = type;
}
public RestResponse(T data, String titleLanguageKey, String title, String messageLanguageKey, String message, ResponseTypeEnum type) {
this.data = data;
this.title = title;
this.titleLanguageKey = titleLanguageKey;
this.message = message;
this.messageLanguageKey = messageLanguageKey;
this.type = type;
}