I have a problem. I had the following code to parse a JSON string to an object:
public AgentStrategy parseJsonToObject(String jsonString) {
Gson gson = new Gson();
AgentStrategy agent = gson.fromJson(jsonString, AgentStrategy.class);
return agent;
}
But now I have a JSON with values that are not equal to the attribute name. Here is the new JSON:
{
"Market": "USDT",
"Coin":"BTC",
"ModuleEnabled":{
"Patterns":{
"Buy":"true",
"Sell":"true"
},
"EMA":{
"Buy":"true",
"Sell":"false"
}
}
}
And this is what the class looks like:
public class AgentStrategy {
public String Market;
public String Coin;
public boolean ModuleEnabledBuyEMA;
public boolean ModuleEnabledSellEMA;
public boolean ModuleEnabledBuyPatterns;
public boolean ModuleEnabledSellPatterns;
public AgentStrategy parseJsonToObject(String jsonString) {
Gson gson = new Gson();
AgentStrategy agent = gson.fromJson(jsonString, AgentStrategy.class);
return agent;
}
}
Now how can I match the JSON and class as the following:
"ModuleEnabled" -> "EMA" -> "Buy" = ModuleEnabledBuyEMA
"ModuleEnabled" -> "EMA" -> "Sell" = ModuleEnabledSellEMA
"ModuleEnabled" -> "Patterns" -> "Buy" = ModuleEnabledBuyPatterns
"ModuleEnabled" -> "Patterns" -> "Sell" = ModuleEnabledSellPatterns