Java Code Examples for org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#isArray()
The following examples show how to use
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#isArray() .
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: Selectors.java From stateful-functions with Apache License 2.0 | 6 votes |
public static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, String> properties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); if (!field.getValue().isTextual()) { throw new WrongTypeException(pointer, "not a key-value pair at " + field); } properties.put(field.getKey(), field.getValue().asText()); } return properties; }
Example 2
Source File: Selectors.java From flink-statefun with Apache License 2.0 | 6 votes |
public static Map<String, String> propertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, String> properties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); properties.put(field.getKey(), field.getValue().asText()); } return properties; }
Example 3
Source File: JsonRowSchemaConverter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
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 4
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
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: Selectors.java From stateful-functions with Apache License 2.0 | 5 votes |
public static Iterable<? extends JsonNode> listAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyList(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a list"); } return node; }
Example 6
Source File: Selectors.java From stateful-functions with Apache License 2.0 | 5 votes |
public static List<String> textListAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyList(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a list"); } return StreamSupport.stream(node.spliterator(), false) .filter(JsonNode::isTextual) .map(JsonNode::asText) .collect(Collectors.toList()); }
Example 7
Source File: Selectors.java From flink-statefun with Apache License 2.0 | 5 votes |
public static Iterable<? extends JsonNode> listAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyList(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a list"); } return node; }
Example 8
Source File: Selectors.java From flink-statefun with Apache License 2.0 | 5 votes |
public static List<String> textListAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyList(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a list"); } return StreamSupport.stream(node.spliterator(), false) .filter(JsonNode::isTextual) .map(JsonNode::asText) .collect(Collectors.toList()); }
Example 9
Source File: Selectors.java From flink-statefun with Apache License 2.0 | 5 votes |
public static Map<String, Long> longPropertiesAt(JsonNode node, JsonPointer pointer) { node = node.at(pointer); if (node.isMissingNode()) { return Collections.emptyMap(); } if (!node.isArray()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map<String, Long> longProperties = new LinkedHashMap<>(); for (JsonNode listElement : node) { Iterator<Map.Entry<String, JsonNode>> fields = listElement.fields(); if (!fields.hasNext()) { throw new WrongTypeException(pointer, "not a key-value list"); } Map.Entry<String, JsonNode> field = fields.next(); if (!field.getValue().isLong() && !field.getValue().isInt()) { throw new WrongTypeException( pointer, "value for key-value pair at " + field.getKey() + " is not a long: " + field.getValue()); } longProperties.put(field.getKey(), field.getValue().asLong()); } return longProperties; }
Example 10
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
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); }