/** * Method called to create a new context for iterating all * contents of the current structured value (JSON array or object) */ public final NodeCursor iterateChildren() { JsonNode n = currentNode(); if (n == null) throw new IllegalStateException("No current node"); if (n.isArray()) { // false since we have already returned START_ARRAY return new Array(n, this); } if (n.isObject()) { return new Object(n, this); } throw new IllegalStateException("Current node of type "+n.getClass().getName()); }
/** * Instantiate a new keystore using the file at the provided path */ public JsonCredentialStore(Path path, KeyToStringCodec codec) throws IOException { credentials = new HashMap<>(); FileSystem fs = path.getFileSystem(new Configuration()); try (InputStream in = fs.open(path)) { ObjectMapper jsonParser = defaultMapper; JsonNode tree = jsonParser.readTree(in); if (!tree.isObject()) { throw new IllegalArgumentException("Json in " + path.toString() + " is not an object!"); } Iterator<Map.Entry<String, JsonNode>> it = tree.getFields(); while (it.hasNext()) { Map.Entry<String, JsonNode> field = it.next(); String keyId = field.getKey(); byte[] key = codec.decodeKey(field.getValue().getTextValue()); credentials.put(keyId, key); } } log.info("Initialized keystore from {} with {} keys", path.toString(), credentials.size()); }
private JsonNode assertIsPlanRoot( String result ) throws JsonParseException { JsonNode json = jsonNode( result ); JsonNode results = json.get( "results" ).get( 0 ); JsonNode plan = results.get( "plan" ); assertTrue( "Expected plan to be an object", plan != null && plan.isObject() ); JsonNode root = plan.get("root"); assertTrue("Expected plan to be an object", root != null && root.isObject()); return root; }
private void parseTypes(JsonNode json) { JsonNode defs = json.get("types"); if (defs == null) return; // no types defined if (!defs.isArray()) throw new SchemaParseException("Types not an array: "+defs); for (JsonNode type : defs) { if (!type.isObject()) throw new SchemaParseException("Type not an object: "+type); Schema.parse(type, types); } }
public TreeTraversingParser(JsonNode n, ObjectCodec codec) { super(0); _objectCodec = codec; if (n.isArray()) { _nextToken = JsonToken.START_ARRAY; _nodeCursor = new NodeCursor.Array(n, null); } else if (n.isObject()) { _nextToken = JsonToken.START_OBJECT; _nodeCursor = new NodeCursor.Object(n, null); } else { // value node _nodeCursor = new NodeCursor.RootValue(n, null); } }
private static Object toObjectFromJSONNode(final JsonNode node) { if (node.isObject()) { final HashMap<String, Object> obj = new HashMap<>(); final Iterator<String> iter = node.getFieldNames();
@Test public void testToJson() throws IOException { GlobalMetadata m = new GlobalMetadata(); m.addTransferEncoding("foo"); m.addTransferEncoding("bar"); byte[] utf8 = m.toJsonUtf8(); String parsed = new String(utf8, StandardCharsets.UTF_8); JsonNode root = new ObjectMapper().readTree(parsed); Assert.assertTrue(root.isObject()); Iterator<JsonNode> children = root.getElements(); int numChildren = 0; while (children.hasNext()) { children.next(); numChildren++; } Assert.assertEquals(numChildren, 3, "expected only 3 child nodes - file, dataset, id"); Assert.assertEquals(root.get("file").size(), 0, "expected no children in file node"); Assert.assertTrue(root.get("id").isTextual(), "expected ID to be textual"); JsonNode transferEncoding = root.get("dataset").get("Transfer-Encoding"); Assert.assertEquals(transferEncoding.size(), m.getTransferEncoding().size()); for (int i = 0; i < m.getTransferEncoding().size(); i++) { Assert.assertEquals(transferEncoding.get(i).getTextValue(), m.getTransferEncoding().get(i)); } }
} else if (jsonNode.isObject()) { Map m = new LinkedHashMap(); for (Iterator<String> it = jsonNode.getFieldNames(); it.hasNext(); ) {
if (fieldNode.isObject()) { RecordSchema childSchema; if (desiredType instanceof RecordDataType) {
if (fieldNode.isObject()) { RecordSchema childSchema; if (desiredType instanceof RecordDataType) {
} else { for (JsonNode child : object.get(DEPENDENCIES)) { if (!child.isObject() || !child.has(FQN) || !child.get(FQN).isTextual() || !child.has(VERSION) || !child.get(VERSION).isInt()) { throw new IllegalArgumentException("Illegal dependency format!");
@Test public void testJsonEmptyRPFormatter() throws Exception { WMFullResourcePlan fullRp = createRP("test_rp_1", null, null); formatter.showFullResourcePlan(out, fullRp); out.flush(); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonTree = objectMapper.readTree(bos.toByteArray()); assertNotNull(jsonTree); assertTrue(jsonTree.isObject()); assertEquals("test_rp_1", jsonTree.get("name").asText()); assertTrue(jsonTree.get("parallelism").isNull()); assertTrue(jsonTree.get("defaultPool").isNull()); assertTrue(jsonTree.get("pools").isArray()); assertEquals(0, jsonTree.get("pools").size()); }
if (fieldNode.isObject()) { RecordSchema childSchema = null; if (dataType != null && RecordFieldType.RECORD == dataType.getFieldType()) {
if (fieldNode.isObject()) { RecordSchema childSchema; if (dataType != null && RecordFieldType.RECORD == dataType.getFieldType()) {
throw new SchemaParseException("Undefined name: "+schema); return result; } else if (schema.isObject()) { Schema result; String type = getRequiredText(schema, "type", "No type");
for ( JsonNode child : root.get( "children" ) ) assertTrue( "Expected object", child.isObject() ); assertEquals( "child", child.get( "operatorType" ).getTextValue() ); identifiers.add( identifiersOf( child ) );
assertTrue(jsonTree.isObject()); assertEquals("test_rp_2", jsonTree.get("name").asText()); assertEquals(10, jsonTree.get("parallelism").asInt());
public TreeTraversingParser(JsonNode n, ObjectCodec codec) { super(0); _objectCodec = codec; if (n.isArray()) { _nextToken = JsonToken.START_ARRAY; _nodeCursor = new NodeCursor.Array(n, null); } else if (n.isObject()) { _nextToken = JsonToken.START_OBJECT; _nodeCursor = new NodeCursor.Object(n, null); } else { // value node _nodeCursor = new NodeCursor.RootValue(n, null); } }