Convert to JSON objects from classes that reference recursively

1

I'm trying to convert two lists of distista classes to JSON.

public class CustomerItem implements Parcelable {
    //...
    private List<ProductItem> mProductList = new ArrayList<>();
...
}

public class ProductItem implements Parcelable {
   //...
    private List<String> mCustomerList;
//...
}

And I have the following function onPause() :

@Override
    protected void onPause() {
        Gson gson = new Gson();
        mJSONProducts = gson.toJson(mBillAccount.getProductItemList());
        mJSONCustomers = gson.toJson(mBillAccount.getCustomerItemList());
        //mBillAccount é objeto da classe BillAccount, que contém as duas listas como membro
        mEditor.putString(KEY_PRODUCT_LIST, mJSONProducts);
        mEditor.putString(KEY_CUSTOMER_LIST, mJSONCustomers);
        /...
        mEditor.apply();
        super.onPause();
    }

Within my onPause() function, I convert the lists with the gson.toJson(), method so that I can redeem them when I restart the app. At that time, according to the memory usage monitor, the app is increasingly consuming the memory of the phone.

With the use of the debugger, I noticed that value passing is never invoked with the mJSONCustomers = gson.toJson(mBillAccount.getCustomerItemList()); method. When reopening the app, the graphical interface freezes (I believe it freezes because it is still trying to generate the JSON). When opening memory usage monitor, I noticed that from that moment the app gradually consumes disk memory. I can not save the mCustomerList member. I tried to use the @Expose(serialize = false, deserialize = false) notation on this member, but it also did not work.

EDITION: When I asked the question, I thought it was a cyclic recursion, as if mCustomerList was of the List<CustomerItem> class instead of List<String> . It was my lack of attention. mCustomerList is of class List<String> . So I think the problem is not cyclic recursion as I said earlier. I apologize for the confusion.

    
asked by anonymous 16.12.2016 / 07:54

0 answers