Please Fix this I m new to android.
I need to be able to edit the value in the @SerializedName annotation with each call. Here’s the JSON response:
{
"rates": {
"INR": { //Problem with INR
"currency_name": "Indian rupee",
"rate": "74.4600",
"rate_for_amount": "74.4600"
}
}
}
Here’s my data class:
public class Rates {
@SerializedName("INR") //Set dynamic serializedName annotation here
private INR INR;
public CurrencyConverterResponse.INR getINR() {
return INR;
}
}
public class INR {
@SerializedName("currency_name")
private String currencyName;
@SerializedName("rate")
private String rate;
@SerializedName("rate_for_amount")
private String rateForAmount;
public String getCurrencyName() {
return currencyName;
}
public String getRate() {
return rate;
}
public String getRateForAmount() {
return rateForAmount;
}
}
2
Answers
If you have limited currencies, So you use like this in Response class
For an unlimited number of options, you should use
Map
so it will return currency name and rate, this solution will work also if you want to receive more than one rate