public String toJSON() { JsonArrayBuilder nodearray = Json.createArrayBuilder(); if (nodeTemplatelist == null) logger.error("nodeTemplatelist is empty"); for (NodeTemplateCount process : nodeTemplatelist) { nodearray.add(process.getCount()); } JsonObject model = Json.createObjectBuilder() .add("name", this.name) .add("plugin_name", this.pluginName) .add("hadoop_version", this.hadoopVersion) .add("node_processes", nodearray) .build(); StringWriter stWriter = new StringWriter(); try (JsonWriter jsonWriter = Json.createWriter(stWriter)) { jsonWriter.writeObject(model); } String jsonData = stWriter.toString(); System.out.println(jsonData); return jsonData; }
public void load(JsonNode json) { setPluginName(json.get("plugin_name").asText()); setName(json.get("name").asText()); setId(json.get("id").asText()); setHadoopVersion(json.get("hadoop_version").asText()); JsonNode node_groups = json.get("node_groups"); Iterator<JsonNode> elements = node_groups.elements(); NodeTemplateCount t = new NodeTemplateCount(); ArrayList<NodeTemplateCount> temp = new ArrayList<NodeTemplateCount>(); while (elements.hasNext()) { JsonNode node = elements.next(); logger.info("node template count" + node.toString()); t.setCount(node.get("count").asInt()); t.setNode(node.get("name").asText()); temp.add(t); } logger.info("Before setNodeTemplatelist"); setNodeTemplatelist(temp); logger.info("After setNodeTemplatelist"); }