List of usage examples for com.google.gson JsonElement isJsonObject
public boolean isJsonObject()
From source file:com.couchbase.cbadmin.assets.NodeGroupList.java
License:Open Source License
public NodeGroupList(JsonObject json) throws RestApiException { JsonElement e = json.get("uri"); if (e == null || e.isJsonPrimitive() == false) { throw new RestApiException("Expected modification URI", json); }/*from ww w . j a v a 2 s . c om*/ assignmentUri = URI.create(e.getAsString()); e = json.get("groups"); if (e == null || e.isJsonArray() == false) { throw new RestApiException("Expected 'groups'", e); } groups = new ArrayList<NodeGroup>(); for (JsonElement groupElem : e.getAsJsonArray()) { if (groupElem.isJsonObject() == false) { throw new RestApiException("Expected object for group", groupElem); } groups.add(new NodeGroup(groupElem.getAsJsonObject())); } }
From source file:com.couchbase.cbadmin.client.ConnectionInfo.java
License:Open Source License
public ConnectionInfo(JsonObject poolsJson) throws RestApiException { JsonElement eTmp; eTmp = poolsJson.get("implementationVersion"); if (eTmp == null) { throw new RestApiException("implementationVersion missing", poolsJson); }//from w w w .j a v a 2 s. co m clusterVersion = eTmp.getAsString(); eTmp = poolsJson.get("pools"); if (eTmp == null || eTmp.isJsonArray() == false) { throw new RestApiException("pools missing", poolsJson); } if (eTmp.getAsJsonArray().size() > 0) { clusterActive = true; eTmp = eTmp.getAsJsonArray().get(0); if (eTmp.isJsonObject() == false) { throw new RestApiException("Expected object in pools entry", eTmp); } eTmp = eTmp.getAsJsonObject().get("uri"); if (eTmp == null || eTmp.isJsonPrimitive() == false) { throw new RestApiException("uri missing or malformed", eTmp); } clusterId = eTmp.getAsString(); } else { clusterActive = false; clusterId = null; } eTmp = poolsJson.get("isAdminCreds"); adminCreds = eTmp != null && eTmp.getAsBoolean(); }
From source file:com.couchbase.cbadmin.client.CouchbaseAdmin.java
License:Open Source License
@Override public Map<String, Bucket> getBuckets() throws RestApiException { JsonElement e;/*from w w w .j av a 2 s . co m*/ Map<String, Bucket> ret = new HashMap<String, Bucket>(); try { e = getJson(P_BUCKETS); } catch (IOException ex) { throw new RestApiException(ex); } JsonArray arr; if (!e.isJsonArray()) { throw new RestApiException("Expected JsonObject", e); } arr = e.getAsJsonArray(); for (int i = 0; i < arr.size(); i++) { JsonElement tmpElem = arr.get(i); if (!tmpElem.isJsonObject()) { throw new RestApiException("Expected JsonObject", tmpElem); } Bucket bucket = new Bucket(tmpElem.getAsJsonObject()); ret.put(bucket.getName(), bucket); } return ret; }
From source file:com.couchbase.cbadmin.client.CouchbaseAdmin.java
License:Open Source License
@Override public NodeGroupList getGroupList() throws RestApiException { JsonElement e; Map<String, NodeGroup> ret = new HashMap<String, NodeGroup>(); try {/*from w ww.jav a 2 s. c o m*/ e = getJson(_P_SERVERGROUPS); } catch (IOException ex) { throw new RestApiException(ex); } if (!e.isJsonObject()) { throw new RestApiException("Expected JSON object", e); } return new NodeGroupList(e.getAsJsonObject()); }
From source file:com.couchbase.cbadmin.client.CouchbaseAdmin.java
License:Open Source License
@Override public List<Node> getNodes() throws RestApiException { List<Node> ret = new ArrayList<Node>(); JsonElement e; try {//from w w w. java 2 s . co m e = getJson(P_POOL_NODES); } catch (IOException ex) { throw new RestApiException(ex); } if (!e.isJsonObject()) { throw new RestApiException("Expected JsonObject", e); } JsonObject obj = e.getAsJsonObject(); JsonArray nodesArr; e = obj.get("nodes"); if (e == null) { throw new RestApiException("Expected 'nodes' array", obj); } nodesArr = e.getAsJsonArray(); for (int i = 0; i < nodesArr.size(); i++) { e = nodesArr.get(i); JsonObject nObj; if (!e.isJsonObject()) { throw new RestApiException("Malformed node entry", e); } nObj = e.getAsJsonObject(); Node n = new Node(nObj); ret.add(n); } return ret; }
From source file:com.couchbase.cbadmin.client.CouchbaseAdmin.java
License:Open Source License
@Override public RebalanceInfo getRebalanceStatus() throws RestApiException { JsonElement js; try {/* w ww . j a v a 2s .c o m*/ js = getResponseJson(new HttpGet(), P_REBALANCE_PROGRESS, 200); } catch (IOException ex) { throw new RestApiException(ex); } if (!js.isJsonObject()) { throw new RestApiException("Expected JSON object", js); } return new RebalanceInfo(js.getAsJsonObject()); }
From source file:com.couchbase.cbadmin.client.CouchbaseAdmin.java
License:Open Source License
@Override public ConnectionInfo getInfo() throws RestApiException { try {/* w ww . ja v a2s. c o m*/ JsonElement js = getResponseJson(new HttpGet(), P_POOLS, 200); if (!js.isJsonObject()) { throw new RestApiException("Expected JSON Object", js); } return new ConnectionInfo(js.getAsJsonObject()); } catch (IOException ex) { throw new RestApiException(ex); } }
From source file:com.crowdmap.java.sdk.json.UsersDeserializer.java
License:Open Source License
@Override public List<User> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { List<User> users = new ArrayList<User>(); if (json.isJsonArray()) { for (JsonElement e : json.getAsJsonArray()) { users.add((User) context.deserialize(e, User.class)); }/*www. j a va2 s . c o m*/ } else if (json.isJsonObject()) { users.add((User) context.deserialize(json, User.class)); } else { throw new CrowdmapException("Unexpected JSON type" + json.getClass()); } return users; }
From source file:com.crypticbit.diff.demo.swing.contacts.JsonJTreeNode.java
License:Apache License
/** * @param fieldName/*from w w w . j a v a 2s . co m*/ * - name of field if applicable or null * @param index * - index of element in the array or -1 if not part of an array * @param jsonElement * - element to represent */ public JsonJTreeNode(String fieldName, int index, JsonElement jsonElement) { this.index = index; this.fieldName = fieldName; if (jsonElement.isJsonArray()) { this.dataType = DataType.ARRAY; this.value = jsonElement.toString(); populateChildren(jsonElement); } else if (jsonElement.isJsonObject()) { this.dataType = DataType.OBJECT; this.value = jsonElement.toString(); populateChildren(jsonElement); } else if (jsonElement.isJsonPrimitive()) { this.dataType = DataType.VALUE; this.value = jsonElement.toString(); } else if (jsonElement.isJsonNull()) { this.dataType = DataType.VALUE; this.value = jsonElement.toString(); } else { throw new IllegalArgumentException("jsonElement is an unknown element type."); } }
From source file:com.crypticbit.diff.demo.swing.JSONJTreeNode.java
License:Apache License
/** * @param fieldName// w w w. j av a 2s. c om * - name of field if applicable or null * @param index * - index of element in the array or -1 if not part of an array * @param jsonElement * - element to represent */ public JSONJTreeNode(String fieldName, int index, JsonElement jsonElement) { this.index = index; this.fieldName = fieldName; if (jsonElement.isJsonArray()) { this.dataType = DataType.ARRAY; this.value = jsonElement.toString(); populateChildren(jsonElement); } else if (jsonElement.isJsonObject()) { this.dataType = DataType.OBJECT; this.value = jsonElement.toString(); populateChildren(jsonElement); } else if (jsonElement.isJsonPrimitive()) { this.dataType = DataType.VALUE; this.value = jsonElement.toString(); } else if (jsonElement.isJsonNull()) { this.dataType = DataType.VALUE; this.value = jsonElement.toString(); } else { throw new IllegalArgumentException("jsonElement is an unknown element type."); } }