com.jelastic.api.users.response.PoliciesResponse Maven / Gradle / Ivy
The newest version!
/*Server class MD5: b1637cf75b4d7e5f47890f5aab0a7204*/
package com.jelastic.api.users.response;
import com.jelastic.api.Response;
import com.jelastic.api.core.persistence.entity.Policy;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
/**
* @name Jelastic API Client
* @version 8.11.2
* @copyright Jelastic, Inc.
*/
public class PoliciesResponse extends Response {
private static final String POLICIES_KEY = "policies";
private List policies;
public PoliciesResponse() {
super(Response.OK());
}
public PoliciesResponse(List policies) {
this();
this.policies = policies;
}
public PoliciesResponse(int result, String error) {
super(result, error);
}
public List getPolicies() {
return policies;
}
public void setPolicies(List policies) {
this.policies = policies;
}
@Override
public JSONObject _toJSON() throws JSONException {
JSONObject json = super._toJSON();
if (policies != null) {
JSONArray jsonArray = new JSONArray();
for (Policy policy : policies) {
jsonArray.put(policy.toJSON());
}
json.put(POLICIES_KEY, jsonArray);
}
return json;
}
@Override
public PoliciesResponse _fromJSON(JSONObject jsonObject) throws JSONException {
super._fromJSON(jsonObject);
if (jsonObject.has(POLICIES_KEY)) {
ArrayList policies = new ArrayList<>();
for (int i = 0; i < jsonObject.getJSONArray(POLICIES_KEY).length(); i++) {
policies.add(new Policy().fromJSON(jsonObject.getJSONArray(POLICIES_KEY).getJSONObject(i)));
}
this.setPolicies(policies);
}
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy