Hi iam trying to dynamically change keys in my retrofit @SerializedName().I am followed this topic and this topic also so i understand that if i want to parse JSON with dynamic keys (with dynamic names) i need to use HashMap.And that what i tried. But with no success..and even worse I'm getting this exception on my ApiCall method that i am calling this endpoint. Also when i comment problematic part of code my app don't crash and get response 200 so it is definitely that i am doing something wrong with trying to parse dynamically keys names
als this is how my code from this example is structured: InvestmentInForceModel -> InvestmentForceRegisteredInvestments-> PercentagesInvestmentInforce
my ApiCall
public Observable<InvestmentInForceModel> getInvestmentsInForce(){
return apiService.getInvestmentsInForce();
}
This is my problematic part of my JSON:
"registeredInvestments": {
"percentages": {
"2": 12.02,
"8": 87.98
},
"registeredInvestmentsData": [//other json stuff]
}
and my model:
public class InvestmentInForceModel {
@SerializedName("registeredInvestments")
private InvestmentForceRegisteredInvestments registeredInvestments;
}
my InvestmentForceRegisteredInvestments
@SerializedName("percentages")
private Map<String,PercentagesInvestmentInforce> stringPercentagesInvestmentInforceMap;
@SerializedName("registeredInvestmentsData")
private List<RegisteredInvestmentsDataModel> registeredInvestmentsDataModelList;
}
and finally :
public class PercentagesInvestmentInforce {
private int investmentsType;
}
private field is without @SerializedName because i don't know what to put there and also this class can be empty if there is nothing send from server ,for example these numbers "2" and "8" sometimes can be only one number that is not 2 or 8 but some else if you understand what i wanted to say.