thiagolocatelli / parse4j

Java Library to deal with Parse (parse.com) REST API
http://thiagolocatelli.github.io/parse4j
143 stars 117 forks source link

Is ParseObject.getParseData() implementation correct? #32

Open sidiabale opened 9 years ago

sidiabale commented 9 years ago

Hi,

I'm wondering if the current implementation of getParseData() in ParseObject is correct. See inline questions below.


public JSONObject getParseData() {
        JSONObject parseData = new JSONObject();

        for(String key : operations.keySet()) {
            ParseFieldOperation operation = (ParseFieldOperation) operations.get(key);
            if(operation instanceof SetFieldOperation) {
                parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
            }
            else if(operation instanceof IncrementFieldOperation) {
                parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
            }
            else if(operation instanceof DeleteFieldOperation) {
                parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
            }
            else if(operation instanceof RelationOperation) {
                parseData.put(key, operation.encode(PointerEncodingStrategy.get()));
            }
            else {
/*
 QUESTIONS: 
1. Every modification of a ParseObject as far as I can see (read: put()) is done via operations. 
So if we get here, I expect that we've encountered an unsupported operation 
NOT a sub-ParseObject. Can you explain why you're expecting a ParseObject here?

2. Why doesn't this code take other operations like AddOperation into account?
*/

                //here we deal will sub objects like ParseObject;
                Object obj = data.get(key);
                if(obj instanceof ParseObject) {
                    ParseObject pob = (ParseObject) obj;
                    parseData.put(key, pob.getParseData());
                }
            }       
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("parseData-> " + parseData);
        }

        return parseData;
    }