0

As you see in the JSON below, I want to represent all the countries in the world. For Firebase de-serialization, I started creating classes like Germany.java, Italy.java, but then it hit me, I have to write 249 classes and in Android when it comes to memory and resource use, what is the best way to do this? Of course I will never initialize more then one at the time.

Was thinking maybe Firebase can do this work, but then I must pay money for that. Was thinking maybe the User's device can download the country he needs, but it might cost me some.

 "LK": {
    "name": "Sri Lanka"
  },
  "SD": {
    "name": "Sudan"
  },
  "SR": {
    "name": "Suriname"
  },
  "SJ": {
    "name": "Svalbard and Jan Mayen"
  },
  "SZ": {
    "name": "Swaziland"
  },
  "SE": {
    "name": "Sweden",
    "ADMINISTRATIVE_AREA_LEVEL_1": {
      "Stockholms län": {
        "LOCALITY": {
          "Stockholm": {
            "STREET_ADDRESS": {
              "Björngatan 36": {
                "id": "KQqv0SYDBP_DMTtJupC",
                "path": "SE/ADMINISTRATIVE_AREA_LEVE...",
                "somekey": ".....",
              }
            }
          }
        }
      }
    }
  },
AL.
  • 36,815
  • 10
  • 142
  • 281
Tord Larsen
  • 2,670
  • 8
  • 33
  • 76
  • Create one class `Country`, with fields `code` (LK, SD, SR etc.) and `name`, then parse json into this class. – mol Oct 13 '16 at 12:27
  • Not sure I understand, Btw, the path `administrative_area_level_1/Stockholms län/locality..` is differerat for maybe half the countries. Like japan have many `administrative_area_level` – Tord Larsen Oct 13 '16 at 12:38
  • Why do you need a separate class for each country? Every country has same or similar fields, they all belong to the same class - Country. Don't name the class by the name of country, just create a field called `name` and write country name to it. – mol Oct 13 '16 at 12:52
  • Yea your right, i will try some – Tord Larsen Oct 13 '16 at 13:07

1 Answers1

0

Have a class named 'Country.java' along with all the common attributes.

Country.java

public class Country
{
     String Name;
     String Code;
}

This allows you to utilize the same properties for multiple scenarios

Jay
  • 4,873
  • 7
  • 72
  • 137