use of org.apache.hbase.thirdparty.com.google.gson.JsonElement in project hbase by apache.
the class RESTApiClusterManager method getServiceName.
// Convert a service (e.g. "HBASE," "HDFS") into a service name (e.g. "HBASE-1," "HDFS-1").
private String getServiceName(Service service) {
String serviceName = null;
URI uri = UriBuilder.fromUri(serverHostname).path("api").path(API_VERSION).path("clusters").path(clusterName).path("services").build();
JsonElement services = parser.parse(getFromURIGet(uri)).getAsJsonObject().get("items");
if (services != null) {
// Iterate through the list of services, stopping once the requested one is found.
for (JsonElement serviceEntry : services.getAsJsonArray()) {
if (serviceEntry.getAsJsonObject().get("type").getAsString().equals(service.toString())) {
serviceName = serviceEntry.getAsJsonObject().get("name").getAsString();
break;
}
}
}
return serviceName;
}
use of org.apache.hbase.thirdparty.com.google.gson.JsonElement in project hbase by apache.
the class ProtobufUtil method toProcedureJson.
/**
* Helper to convert the protobuf Procedure to JSON String
* @return Convert the current Protocol Buffers Procedure to JSON String
*/
public static String toProcedureJson(List<ProcedureProtos.Procedure> procProtos) {
JsonArray procJsons = new JsonArray(procProtos.size());
for (ProcedureProtos.Procedure procProto : procProtos) {
try {
JsonElement procJson = ProtobufMessageConverter.toJsonElement(procProto);
procJsons.add(procJson);
} catch (InvalidProtocolBufferException e) {
procJsons.add(e.toString());
}
}
return procJsons.toString();
}
use of org.apache.hbase.thirdparty.com.google.gson.JsonElement in project hbase by apache.
the class ProtobufMessageConverter method toJavaObject.
private static Object toJavaObject(JsonElement element) {
if (element.isJsonNull()) {
return null;
} else if (element.isJsonPrimitive()) {
JsonPrimitive primitive = element.getAsJsonPrimitive();
if (primitive.isBoolean()) {
return primitive.getAsBoolean();
} else if (primitive.isNumber()) {
return primitive.getAsNumber();
} else if (primitive.isString()) {
return primitive.getAsString();
} else {
return null;
}
} else if (element.isJsonArray()) {
JsonArray array = element.getAsJsonArray();
List<Object> list = new ArrayList<>();
for (JsonElement arrayElement : array) {
Object javaObject = toJavaObject(arrayElement);
list.add(javaObject);
}
return list;
} else if (element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
Map<String, Object> map = new LinkedHashMap<>();
for (Entry<String, JsonElement> entry : object.entrySet()) {
Object javaObject = toJavaObject(entry.getValue());
map.put(entry.getKey(), javaObject);
}
return map;
} else {
return null;
}
}
Aggregations