Parse4cn1 recreate user from cached data

40 Views Asked by At

I'm trying to create a caching system for data downloaded from parse in my cn1 app, so that the app doesn't have to make a network call every time. I don't want to use the built in externalization implementation built into the parse4cn1 lib, because as I understand it writes each object to a file, and I want to cache whole queries with large lists of objects.

I ran into a problem trying to restore ParseUser objects (such as members of the current user's team) that were previously queried. I don't see any way to instantiate the ParseUser object without extending the class. Is that what I should be doing, or is there some other way to get around this problem?

My hesitation is that beyond this need I have no reason to subclass ParseUser, and if I register my subclass I assume it will have to use a different class name, and it will require a significant readjustment of other parts of my code.

Update

I subclassed ParseUser in order to expose an empty constructor, and thanks to polymorphism I didn't have to change any other code. It looks like this:

    public static class MyParseUser extends ParseUser{
        public static ParseUser fromData(JSONObject data){
            ParseUser user = new VqParseUser();
            user.setData(data);
            return user;
        }

        private MyParseUser(){
            super();
        }
    }

And then, in my code:

ParseUser parseUser = MyParseUser.fromData(json);

I'm still curious if this was the best approach.

0

There are 0 best solutions below