I'm currently calling this API https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/gbp.json
This has the path param of gbp
which then is included in the response
{
"date": "2021-09-14",
"gbp": {
// omitted for brevity
}
}
Im using the RestTemplate.getForObject
method to make the GET HTTP request which is successful however i am not sure how i would go about typing the response.
I will be calling this url with multiple different path parameters. So for example https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/eur.json is valid which will result in a response of
{
"date": "2021-09-14",
"eur": {
// omitted for brevity
}
}
So its not as easy as typing a gbp
property on the response as Map<String, Double>
etc. And i dont want to create a different class for each possible response.
So my question basically is. How can i type this? I've tried to use a custom @JsonDeserialzer
annotation on a class which represents the data however since it does not know the key that was a bit of a dead end.
Is the only way to achieve this by using a custom ObjectMapper
where i can pass the key to a customer deserializer rather than using the annotation?