Java Code Examples for org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#isObject()

The following examples show how to use org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#isObject() . 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: JsonRowSchemaConverter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static TypeInformation<Row> convertObject(String location, JsonNode node, JsonNode root) {
	// validate properties
	if (!node.has(PROPERTIES)) {
		return Types.ROW();
	}
	if (!node.isObject()) {
		throw new IllegalArgumentException(
			"Invalid '" + PROPERTIES + "' property for object type in node: " + location);
	}
	final JsonNode props = node.get(PROPERTIES);
	final String[] names = new String[props.size()];
	final TypeInformation<?>[] types = new TypeInformation[props.size()];

	final Iterator<Map.Entry<String, JsonNode>> fieldIter = props.fields();
	int i = 0;
	while (fieldIter.hasNext()) {
		final Map.Entry<String, JsonNode> subNode = fieldIter.next();

		// set field name
		names[i] = subNode.getKey();

		// set type
		types[i] = convertType(location + '/' + subNode.getKey(), subNode.getValue(), root);

		i++;
	}

	// validate that object does not contain additional properties
	if (node.has(ADDITIONAL_PROPERTIES) && node.get(ADDITIONAL_PROPERTIES).isBoolean() &&
			node.get(ADDITIONAL_PROPERTIES).asBoolean()) {
		throw new IllegalArgumentException(
			"An object must not allow additional properties in node: " + location);
	}

	return Types.ROW_NAMED(names, types);
}
 
Example 2
Source File: JsonRowSchemaConverter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static TypeInformation<?> convertArray(String location, JsonNode node, JsonNode root) {
	// validate items
	if (!node.has(ITEMS)) {
		throw new IllegalArgumentException(
			"Arrays must specify an '" + ITEMS + "' property in node: " + location);
	}
	final JsonNode items = node.get(ITEMS);

	// list (translated to object array)
	if (items.isObject()) {
		final TypeInformation<?> elementType = convertType(
			location + '/' + ITEMS,
			items,
			root);
		// result type might either be ObjectArrayTypeInfo or BasicArrayTypeInfo for Strings
		return Types.OBJECT_ARRAY(elementType);
	}
	// tuple (translated to row)
	else if (items.isArray()) {
		final TypeInformation<?>[] types = convertTypes(location + '/' + ITEMS, items, root);

		// validate that array does not contain additional items
		if (node.has(ADDITIONAL_ITEMS) && node.get(ADDITIONAL_ITEMS).isBoolean() &&
				node.get(ADDITIONAL_ITEMS).asBoolean()) {
			throw new IllegalArgumentException(
				"An array tuple must not allow additional items in node: " + location);
		}

		return Types.ROW(types);
	}
	throw new IllegalArgumentException(
		"Invalid type for '" + ITEMS + "' property in node: " + location);
}
 
Example 3
Source File: JsonRowSchemaConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private static TypeInformation<Row> convertObject(String location, JsonNode node, JsonNode root) {
	// validate properties
	if (!node.has(PROPERTIES)) {
		return Types.ROW();
	}
	if (!node.isObject()) {
		throw new IllegalArgumentException(
			"Invalid '" + PROPERTIES + "' property for object type in node: " + location);
	}
	final JsonNode props = node.get(PROPERTIES);
	final String[] names = new String[props.size()];
	final TypeInformation<?>[] types = new TypeInformation[props.size()];

	final Iterator<Map.Entry<String, JsonNode>> fieldIter = props.fields();
	int i = 0;
	while (fieldIter.hasNext()) {
		final Map.Entry<String, JsonNode> subNode = fieldIter.next();

		// set field name
		names[i] = subNode.getKey();

		// set type
		types[i] = convertType(location + '/' + subNode.getKey(), subNode.getValue(), root);

		i++;
	}

	// validate that object does not contain additional properties
	if (node.has(ADDITIONAL_PROPERTIES) && node.get(ADDITIONAL_PROPERTIES).isBoolean() &&
			node.get(ADDITIONAL_PROPERTIES).asBoolean()) {
		throw new IllegalArgumentException(
			"An object must not allow additional properties in node: " + location);
	}

	return Types.ROW_NAMED(names, types);
}
 
Example 4
Source File: JsonRowSchemaConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private static TypeInformation<?> convertArray(String location, JsonNode node, JsonNode root) {
	// validate items
	if (!node.has(ITEMS)) {
		throw new IllegalArgumentException(
			"Arrays must specify an '" + ITEMS + "' property in node: " + location);
	}
	final JsonNode items = node.get(ITEMS);

	// list (translated to object array)
	if (items.isObject()) {
		final TypeInformation<?> elementType = convertType(
			location + '/' + ITEMS,
			items,
			root);
		// result type might either be ObjectArrayTypeInfo or BasicArrayTypeInfo for Strings
		return Types.OBJECT_ARRAY(elementType);
	}
	// tuple (translated to row)
	else if (items.isArray()) {
		final TypeInformation<?>[] types = convertTypes(location + '/' + ITEMS, items, root);

		// validate that array does not contain additional items
		if (node.has(ADDITIONAL_ITEMS) && node.get(ADDITIONAL_ITEMS).isBoolean() &&
				node.get(ADDITIONAL_ITEMS).asBoolean()) {
			throw new IllegalArgumentException(
				"An array tuple must not allow additional items in node: " + location);
		}

		return Types.ROW(types);
	}
	throw new IllegalArgumentException(
		"Invalid type for '" + ITEMS + "' property in node: " + location);
}
 
Example 5
Source File: JsonRowSchemaConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private static TypeInformation<Row> convertObject(String location, JsonNode node, JsonNode root) {
	// validate properties
	if (!node.has(PROPERTIES)) {
		return Types.ROW();
	}
	if (!node.isObject()) {
		throw new IllegalArgumentException(
			"Invalid '" + PROPERTIES + "' property for object type in node: " + location);
	}
	final JsonNode props = node.get(PROPERTIES);
	final String[] names = new String[props.size()];
	final TypeInformation<?>[] types = new TypeInformation[props.size()];

	final Iterator<Map.Entry<String, JsonNode>> fieldIter = props.fields();
	int i = 0;
	while (fieldIter.hasNext()) {
		final Map.Entry<String, JsonNode> subNode = fieldIter.next();

		// set field name
		names[i] = subNode.getKey();

		// set type
		types[i] = convertType(location + '/' + subNode.getKey(), subNode.getValue(), root);

		i++;
	}

	// validate that object does not contain additional properties
	if (node.has(ADDITIONAL_PROPERTIES) && node.get(ADDITIONAL_PROPERTIES).isBoolean() &&
			node.get(ADDITIONAL_PROPERTIES).asBoolean()) {
		throw new IllegalArgumentException(
			"An object must not allow additional properties in node: " + location);
	}

	return Types.ROW_NAMED(names, types);
}
 
Example 6
Source File: JsonRowSchemaConverter.java    From flink with Apache License 2.0 5 votes vote down vote up
private static TypeInformation<?> convertArray(String location, JsonNode node, JsonNode root) {
	// validate items
	if (!node.has(ITEMS)) {
		throw new IllegalArgumentException(
			"Arrays must specify an '" + ITEMS + "' property in node: " + location);
	}
	final JsonNode items = node.get(ITEMS);

	// list (translated to object array)
	if (items.isObject()) {
		final TypeInformation<?> elementType = convertType(
			location + '/' + ITEMS,
			items,
			root);
		// result type might either be ObjectArrayTypeInfo or BasicArrayTypeInfo for Strings
		return Types.OBJECT_ARRAY(elementType);
	}
	// tuple (translated to row)
	else if (items.isArray()) {
		final TypeInformation<?>[] types = convertTypes(location + '/' + ITEMS, items, root);

		// validate that array does not contain additional items
		if (node.has(ADDITIONAL_ITEMS) && node.get(ADDITIONAL_ITEMS).isBoolean() &&
				node.get(ADDITIONAL_ITEMS).asBoolean()) {
			throw new IllegalArgumentException(
				"An array tuple must not allow additional items in node: " + location);
		}

		return Types.ROW(types);
	}
	throw new IllegalArgumentException(
		"Invalid type for '" + ITEMS + "' property in node: " + location);
}