Package com.rallydev.rest.response

Source Code of com.rallydev.rest.response.GetResponse

package com.rallydev.rest.response;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.util.Map;

/**
* Represents a WSAPI response from retrieving a single object.
*/
public class GetResponse extends Response {

    /**
     * Create a new get response from the specified JSON encoded string.
     *
     * @param getResponse the JSON encoded string
     */
    public GetResponse(String getResponse) {
        super(getResponse);
    }

    /**
     * Get the name of the root JSON result
     *
     * @return the root element name
     */
    @Override
    protected String getRoot() {
        JsonObject result = ((JsonObject) new JsonParser().parse(raw));
        String root = null;
        for(Map.Entry<String, JsonElement> member : result.entrySet()) {
            root = member.getKey();
        }
        return root;
    }

    /**
     * Get the retrieved object.
     * <p>Returns null if the operation was not successful</p>
     * @return the retrieved object
     */
    public JsonObject getObject() {
        return wasSuccessful() ? result : null;
    }
}
TOP

Related Classes of com.rallydev.rest.response.GetResponse

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.