Java Code Examples for com.fasterxml.jackson.core.TreeNode#size()
The following examples show how to use
com.fasterxml.jackson.core.TreeNode#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceSitePass.java From incubator-nemo with Apache License 2.0 | 6 votes |
/** * @param jsonString serialized bandwidth specification. * @return the bandwidth specification. */ static BandwidthSpecification fromJsonString(final String jsonString) { final BandwidthSpecification specification = new BandwidthSpecification(); try { final ObjectMapper objectMapper = new ObjectMapper(); final TreeNode jsonRootNode = objectMapper.readTree(jsonString); for (int i = 0; i < jsonRootNode.size(); i++) { final TreeNode locationNode = jsonRootNode.get(i); final String name = locationNode.get("name").traverse().nextTextValue(); final int up = locationNode.get("up").traverse().getIntValue(); final int down = locationNode.get("down").traverse().getIntValue(); specification.nodeNames.add(name); specification.uplinkBandwidth.put(name, up); specification.downlinkBandwidth.put(name, down); } } catch (final IOException e) { throw new RuntimeException(e); } return specification; }
Example 2
Source File: KnoxShellTableRowDeserializer.java From knox with Apache License 2.0 | 6 votes |
private List<KnoxShellTableCall> parseCallHistoryListJSONNode(TreeNode callHistoryNode) throws IOException { final List<KnoxShellTableCall> callHistoryList = new LinkedList<>(); TreeNode callNode; Map<Object, Class<?>> params; String invokerClass, method; Boolean builderMethod; for (int i = 0; i < callHistoryNode.size(); i++) { callNode = callHistoryNode.get(i); invokerClass = trimJSONQuotes(callNode.get("invokerClass").toString()); method = trimJSONQuotes(callNode.get("method").toString()); builderMethod = Boolean.valueOf(trimJSONQuotes(callNode.get("builderMethod").toString())); params = fetchParameterMap(callNode.get("params")); callHistoryList.add(new KnoxShellTableCall(invokerClass, method, builderMethod, params)); } return callHistoryList; }
Example 3
Source File: KnoxShellTableRowDeserializer.java From knox with Apache License 2.0 | 6 votes |
private KnoxShellTable parseJsonWithData(final TreeNode jsonContent) { if (jsonContent.get("title").size() != 0) { table.title(trimJSONQuotes(jsonContent.get("title").toString())); } final TreeNode headers = jsonContent.get("headers"); for (int i = 0; i < headers.size(); i++) { table.header(trimJSONQuotes(headers.get(i).toString())); } final TreeNode rows = jsonContent.get("rows"); for (int i = 0; i < rows.size(); i++) { TreeNode row = rows.get(i); table.row(); for (int j = 0; j < row.size(); j++) { table.value(trimJSONQuotes(row.get(j).toString())); } } return table; }
Example 4
Source File: JSONParser.java From Halyard with Apache License 2.0 | 5 votes |
private void hash(TreeNode node) { if (node.isArray()) { md.update((byte)'l'); for (int i = 0; i < node.size(); i++) { hash(node.get(i)); } md.update((byte)'e'); } else if (node.isObject()) { String[] fieldNames = new String[node.size()]; Iterator<String> it = node.fieldNames(); for (int i=0; i< fieldNames.length; i++) { fieldNames[i] = it.next(); } Arrays.sort(fieldNames); md.update((byte)'d'); for (String fName : fieldNames) { hash(fName); hash(node.get(fName)); } md.update((byte)'e'); } else if (node.isValueNode()) { String val = ((JsonNode)node).textValue(); if (val != null) { hash(val); } } else { throw new IllegalArgumentException(node.toString()); } }
Example 5
Source File: PostgresqlTest.java From mybatis-jackson with MIT License | 5 votes |
protected void compareArrays(TreeNode a, TreeNode b) { assertThat(a.isArray()).isEqualTo(b.isArray()); assertThat(a.size()).isEqualTo(b.size()); for (int i = 0; i < a.size(); i++) { assertThat(a.get(i)).isEqualTo(b.get(i)); } }
Example 6
Source File: Util.java From incubator-nemo with Apache License 2.0 | 4 votes |
/** * Utility method for parsing the resource specification string. * * @param resourceSpecificationString the input resource specification string. * @return the parsed list of resource specifications. The Integer indicates how many of the specified nodes are * required, followed by the ResourceSpecification that indicates the specifications of the nodes. */ public static List<Pair<Integer, ResourceSpecification>> parseResourceSpecificationString( final String resourceSpecificationString) { final List<Pair<Integer, ResourceSpecification>> resourceSpecifications = new ArrayList<>(); try { if (resourceSpecificationString.trim().startsWith("[")) { final TreeNode jsonRootNode = new ObjectMapper().readTree(resourceSpecificationString); for (int i = 0; i < jsonRootNode.size(); i++) { final TreeNode resourceNode = jsonRootNode.get(i); final int executorNum = resourceNode.path("num").traverse().nextIntValue(1); final String type = resourceNode.get("type").traverse().nextTextValue(); final int capacity = resourceNode.get("capacity").traverse().getIntValue(); final int memory = resourceNode.get("memory_mb").traverse().getIntValue(); final OptionalDouble maxOffheapRatio; final OptionalInt poisonSec; if (resourceNode.path("max_offheap_ratio").traverse().nextToken() == JsonToken.VALUE_NUMBER_FLOAT) { maxOffheapRatio = OptionalDouble.of(resourceNode.path("max_offheap_ratio").traverse().getDoubleValue()); } else { maxOffheapRatio = OptionalDouble.empty(); } if (resourceNode.path("poison_sec").traverse().nextToken() == JsonToken.VALUE_NUMBER_INT) { poisonSec = OptionalInt.of(resourceNode.path("poison_sec").traverse().getIntValue()); } else { poisonSec = OptionalInt.empty(); } resourceSpecifications.add( Pair.of(executorNum, new ResourceSpecification(type, capacity, memory, maxOffheapRatio, poisonSec))); } } else { throw new UnsupportedOperationException("Executor Info file should be a JSON file."); } return resourceSpecifications; } catch (final Exception e) { throw new JsonParseException(e); } }