Java Code Examples for org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#fields()
The following examples show how to use
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#fields() .
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<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 |
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 5
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 6
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 5 votes |
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); }