Below are two responses from 2 different APIs. The structure of the responses is the same, but the names of the two variables are different. How do I create a single entity class where I can save the responses?
First API:
"""
{
"success": true,
"timestamp": 1519296206,
"base": "USD",
"rates": {
"GBP": 0.72007,
"JPY": 107.346001,
"EUR": 0.813399,
}
}
"""
Second API:
"""
{
"success": true,
"timestamp": 1432400348,
"source": "USD",
"quotes": {
"USDAUD": 1.278342,
"USDEUR": 1.278342,
"USDGBP": 0.908019,
"USDPLN": 3.731504
}
}
"""
My service method for first API:
@Override
public FixerCurrency getEuro() {
httpHeaders.setAccept(List.of(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<>(httpHeaders);
ResponseEntity<FixerCurrency> response = restTemplate.exchange(fixerApi, HttpMethod.GET, entity, FixerCurrency.class);
return response.getBody();
}
My service method for second API:
@Override
public CurrencylayerCurrency getDollar() {
httpHeaders.setAccept(List.of(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<>(httpHeaders);
ResponseEntity<CurrencylayerCurrency> response = restTemplate.exchange(currencylayerApi, HttpMethod.GET, entity, CurrencylayerCurrency.class);
return response.getBody();
}