1

The JSON I am trying to parse looks like this:

{
   "date": "2018-10-18",
   "rates": {
       "BGN": 1.6999565406,
       "CAD": 1.3045632334,
       "BRL": 3.6899608866
       ...
   }
}

I do not know what K-V pairs would be present in the rates object. I want to parse such a JSON structure using GSON, so I created this model class

public class Rates {
    public Date date;
}

How do I extract the underlying K-V pairs inside rates using GSON?

PS. My question is different from this as that guy had a varied top-level object. For me, the underlying key-value pairs are dynamic and not known

Sparker0i
  • 1,787
  • 4
  • 35
  • 60

1 Answers1

3

You may add a new property called rates of type Map<String, Double> to your Rates class. GSON should map those Key-Value pairs to the map without any additional configuration.

Bifz
  • 403
  • 2
  • 9