Common json interface for Android / Java

I am writing an Android application that can export the current state Activityor Fragmentto a JSON file, which has the following general format:

{
  "data": {
    "result": {
      <content depends on specific class>
    },
    "input": {
      <content depends on specific class>
    }
  },
  "identifier": <identifier depends on specific class>,
  "version": 1
}

This means that Activities/ Fragments, which have the ability to export the filling with marked content, implements the interface that I called "Exportable", and the general export function calls the methods defined in the interface. This is a complex solution that works quite well.

So far so good. Now I want to do the opposite direction. I want to upload a file and call the appropriate Activity/ Fragmentdepending on the contents of the identifier.

"" "" Activity/Fragment.

, , . ? , .

+5
3

. Google GSON, JSON Java . , Java.

0

JSONObject js = JSONObject ( "" );

JSONObject jSObject1 = js.getJSONObject( "" ); JSONObject jSObject2 = js.getJSONObject( "enter" ); , .

0

. -else , , Factory.

ExportableFactory, Exportable Activity Fragment. Map<String, ExportableFactory>, identifier factory. :

Exportable exportable = factoryMap.get(identifier).createExportable(data);

, Exportable, ExportableFactory .

0

All Articles