Json string for sphere objects, fastest way

I have the following code that I run in AsyncTask. It works well, but the following lines seem to make it 3-5 seconds slower to use. Is there a faster way to convert my json string to scope?

    //Load the local model data. params[0].toString() is a json string loaded from SharedPreferences.
    JsonParser jsonParser = new JsonParser();
    JsonObject o = (JsonObject)jsonParser.parse(params[0].toString());

    Realm realmThread = Realm.getInstance(visnetawrap.appModel);

    //work orders, total entries of 4000.
    JsonArray openWorkOrders = o.getAsJsonArray("work_orders");

    //Convert the lists so they can be used with realm.
    List<OpenOrderObject> woList = visnetawrap.gsonClient.fromJson(openWorkOrders.toString(), new TypeToken<List<OpenOrderObject>>() {
    }.getType());
    realmThread.beginTransaction();
    realmThread.copyToRealm(woList);
    realmThread.commitTransaction();
+4
source share
1 answer

It depends on how much your JSON matches your model classes. In the above code, it seems to you that you are doing a lot of extra work, converting between the string representation and the object model 2 times.

JSON 1:1, realm.createAllFromJson(OpenOrderObject.class, openWorkOrders). GSON, GSON - . : https://realm.io/docs/java/latest/api/io/realm/Realm.html#createAllFromJson-java.lang.Class-org.json.JSONArray-.

, , , (, , , SharedPreferences), , Realm , , , , .

+4

All Articles