Java Code Examples for org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#asText()
The following examples show how to use
org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode#asText() .
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 | 6 votes |
private static TypeInformation<?> convertStringFormat(String location, JsonNode node) { if (!node.isTextual()) { throw new IllegalArgumentException("Invalid '" + FORMAT + "' property in node: " + location); } switch (node.asText()) { case FORMAT_DATE: return Types.SQL_DATE; case FORMAT_TIME: return Types.SQL_TIME; case FORMAT_DATE_TIME: return Types.SQL_TIMESTAMP; default: return Types.STRING; // unlikely that we will support other formats in the future } }
Example 2
Source File: JsonRowSchemaConverter.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
private static TypeInformation<?> convertStringEncoding(String location, JsonNode node) { if (!node.isTextual()) { throw new IllegalArgumentException("Invalid '" + CONTENT_ENCODING + "' property in node: " + location); } // "If the instance value is a string, this property defines that the string SHOULD // be interpreted as binary data and decoded using the encoding named by this property." switch (node.asText()) { case CONTENT_ENCODING_BASE64: return Types.PRIMITIVE_ARRAY(Types.BYTE); default: // we fail hard here: // this gives us the chance to support more encodings in the future without problems // of backwards compatibility throw new IllegalArgumentException("Invalid encoding '" + node.asText() + "' in node: " + location); } }
Example 3
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 6 votes |
private static TypeInformation<?> convertStringFormat(String location, JsonNode node) { if (!node.isTextual()) { throw new IllegalArgumentException("Invalid '" + FORMAT + "' property in node: " + location); } switch (node.asText()) { case FORMAT_DATE: return Types.SQL_DATE; case FORMAT_TIME: return Types.SQL_TIME; case FORMAT_DATE_TIME: return Types.SQL_TIMESTAMP; default: return Types.STRING; // unlikely that we will support other formats in the future } }
Example 4
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 6 votes |
private static TypeInformation<?> convertStringEncoding(String location, JsonNode node) { if (!node.isTextual()) { throw new IllegalArgumentException("Invalid '" + CONTENT_ENCODING + "' property in node: " + location); } // "If the instance value is a string, this property defines that the string SHOULD // be interpreted as binary data and decoded using the encoding named by this property." switch (node.asText()) { case CONTENT_ENCODING_BASE64: return Types.PRIMITIVE_ARRAY(Types.BYTE); default: // we fail hard here: // this gives us the chance to support more encodings in the future without problems // of backwards compatibility throw new IllegalArgumentException("Invalid encoding '" + node.asText() + "' in node: " + location); } }
Example 5
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 6 votes |
private static TypeInformation<?> convertStringFormat(String location, JsonNode node) { if (!node.isTextual()) { throw new IllegalArgumentException("Invalid '" + FORMAT + "' property in node: " + location); } switch (node.asText()) { case FORMAT_DATE: return Types.SQL_DATE; case FORMAT_TIME: return Types.SQL_TIME; case FORMAT_DATE_TIME: return Types.SQL_TIMESTAMP; default: return Types.STRING; // unlikely that we will support other formats in the future } }
Example 6
Source File: JsonRowSchemaConverter.java From flink with Apache License 2.0 | 6 votes |
private static TypeInformation<?> convertStringEncoding(String location, JsonNode node) { if (!node.isTextual()) { throw new IllegalArgumentException("Invalid '" + CONTENT_ENCODING + "' property in node: " + location); } // "If the instance value is a string, this property defines that the string SHOULD // be interpreted as binary data and decoded using the encoding named by this property." switch (node.asText()) { case CONTENT_ENCODING_BASE64: return Types.PRIMITIVE_ARRAY(Types.BYTE); default: // we fail hard here: // this gives us the chance to support more encodings in the future without problems // of backwards compatibility throw new IllegalArgumentException("Invalid encoding '" + node.asText() + "' in node: " + location); } }
Example 7
Source File: JsonServiceLoader.java From stateful-functions with Apache License 2.0 | 5 votes |
private static void validateMeta(URL moduleYamlFile, JsonNode root) { JsonNode typeNode = root.at(MODULE_META_TYPE); if (typeNode.isMissingNode()) { throw new IllegalStateException("Unable to find a module type in " + moduleYamlFile); } if (!typeNode.asText().equalsIgnoreCase(ModuleType.REMOTE.name())) { throw new IllegalStateException( "Unknown module type " + typeNode.asText() + ", currently supported: " + ModuleType.REMOTE); } }
Example 8
Source File: Selectors.java From stateful-functions with Apache License 2.0 | 5 votes |
public static String textAt(JsonNode node, JsonPointer pointer) { node = dereference(node, pointer); if (!node.isTextual()) { throw new WrongTypeException(pointer, "not a string"); } return node.asText(); }
Example 9
Source File: Selectors.java From flink-statefun with Apache License 2.0 | 5 votes |
public static String textAt(JsonNode node, JsonPointer pointer) { node = dereference(node, pointer); if (!node.isTextual()) { throw new WrongTypeException(pointer, "not a string"); } return node.asText(); }
Example 10
Source File: JsonServiceLoader.java From flink-statefun with Apache License 2.0 | 5 votes |
private static void validateMeta(URL moduleYamlFile, JsonNode root) { JsonNode typeNode = root.at(MODULE_META_TYPE); if (typeNode.isMissingNode()) { throw new IllegalStateException("Unable to find a module type in " + moduleYamlFile); } if (!typeNode.asText().equalsIgnoreCase(ModuleType.REMOTE.name())) { throw new IllegalStateException( "Unknown module type " + typeNode.asText() + ", currently supported: " + ModuleType.REMOTE); } }
Example 11
Source File: JsonRowDeserializationSchema.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private Object convert(JsonNode node, TypeInformation<?> info) { if (info == Types.VOID || node.isNull()) { return null; } else if (info == Types.BOOLEAN) { return node.asBoolean(); } else if (info == Types.STRING) { return node.asText(); } else if (info == Types.BIG_DEC) { return node.decimalValue(); } else if (info == Types.BIG_INT) { return node.bigIntegerValue(); } else if (info == Types.SQL_DATE) { return Date.valueOf(node.asText()); } else if (info == Types.SQL_TIME) { // according to RFC 3339 every full-time must have a timezone; // until we have full timezone support, we only support UTC; // users can parse their time as string as a workaround final String time = node.asText(); if (time.indexOf('Z') < 0 || time.indexOf('.') >= 0) { throw new IllegalStateException( "Invalid time format. Only a time in UTC timezone without milliseconds is supported yet. " + "Format: HH:mm:ss'Z'"); } return Time.valueOf(time.substring(0, time.length() - 1)); } else if (info == Types.SQL_TIMESTAMP) { // according to RFC 3339 every date-time must have a timezone; // until we have full timezone support, we only support UTC; // users can parse their time as string as a workaround final String timestamp = node.asText(); if (timestamp.indexOf('Z') < 0) { throw new IllegalStateException( "Invalid timestamp format. Only a timestamp in UTC timezone is supported yet. " + "Format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); } return Timestamp.valueOf(timestamp.substring(0, timestamp.length() - 1).replace('T', ' ')); } else if (info instanceof RowTypeInfo) { return convertRow(node, (RowTypeInfo) info); } else if (info instanceof ObjectArrayTypeInfo) { return convertObjectArray(node, ((ObjectArrayTypeInfo) info).getComponentInfo()); } else if (info instanceof BasicArrayTypeInfo) { return convertObjectArray(node, ((BasicArrayTypeInfo) info).getComponentInfo()); } else if (info instanceof PrimitiveArrayTypeInfo && ((PrimitiveArrayTypeInfo) info).getComponentType() == Types.BYTE) { return convertByteArray(node); } else { // for types that were specified without JSON schema // e.g. POJOs try { return objectMapper.treeToValue(node, info.getTypeClass()); } catch (JsonProcessingException e) { throw new IllegalStateException("Unsupported type information '" + info + "' for node: " + node); } } }
Example 12
Source File: JsonJobGraphGenerationTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public void validateJson(String json) throws Exception { final Map<String, JsonNode> idToNode = new HashMap<>(); // validate the produced JSON ObjectMapper m = new ObjectMapper(); JsonNode rootNode = m.readTree(json); JsonNode idField = rootNode.get("jid"); JsonNode nameField = rootNode.get("name"); JsonNode arrayField = rootNode.get("nodes"); assertNotNull(idField); assertNotNull(nameField); assertNotNull(arrayField); assertTrue(idField.isTextual()); assertTrue(nameField.isTextual()); assertTrue(arrayField.isArray()); ArrayNode array = (ArrayNode) arrayField; Iterator<JsonNode> iter = array.elements(); while (iter.hasNext()) { JsonNode vertex = iter.next(); JsonNode vertexIdField = vertex.get("id"); JsonNode parallelismField = vertex.get("parallelism"); JsonNode contentsFields = vertex.get("description"); JsonNode operatorField = vertex.get("operator"); assertNotNull(vertexIdField); assertTrue(vertexIdField.isTextual()); assertNotNull(parallelismField); assertTrue(parallelismField.isNumber()); assertNotNull(contentsFields); assertTrue(contentsFields.isTextual()); assertNotNull(operatorField); assertTrue(operatorField.isTextual()); if (contentsFields.asText().startsWith("Sync")) { assertEquals(1, parallelismField.asInt()); } else { assertEquals(expectedParallelism, parallelismField.asInt()); } idToNode.put(vertexIdField.asText(), vertex); } assertEquals(numNodes, idToNode.size()); // check that all inputs are contained for (JsonNode node : idToNode.values()) { JsonNode inputsField = node.get("inputs"); if (inputsField != null) { Iterator<JsonNode> inputsIter = inputsField.elements(); while (inputsIter.hasNext()) { JsonNode inputNode = inputsIter.next(); JsonNode inputIdField = inputNode.get("id"); assertNotNull(inputIdField); assertTrue(inputIdField.isTextual()); String inputIdString = inputIdField.asText(); assertTrue(idToNode.containsKey(inputIdString)); } } } }
Example 13
Source File: JsonJobGraphGenerationTest.java From flink with Apache License 2.0 | 4 votes |
@Override public void validateJson(String json) throws Exception { final Map<String, JsonNode> idToNode = new HashMap<>(); // validate the produced JSON ObjectMapper m = new ObjectMapper(); JsonNode rootNode = m.readTree(json); JsonNode idField = rootNode.get("jid"); JsonNode nameField = rootNode.get("name"); JsonNode arrayField = rootNode.get("nodes"); assertNotNull(idField); assertNotNull(nameField); assertNotNull(arrayField); assertTrue(idField.isTextual()); assertTrue(nameField.isTextual()); assertTrue(arrayField.isArray()); ArrayNode array = (ArrayNode) arrayField; Iterator<JsonNode> iter = array.elements(); while (iter.hasNext()) { JsonNode vertex = iter.next(); JsonNode vertexIdField = vertex.get("id"); JsonNode parallelismField = vertex.get("parallelism"); JsonNode contentsFields = vertex.get("description"); JsonNode operatorField = vertex.get("operator"); assertNotNull(vertexIdField); assertTrue(vertexIdField.isTextual()); assertNotNull(parallelismField); assertTrue(parallelismField.isNumber()); assertNotNull(contentsFields); assertTrue(contentsFields.isTextual()); assertNotNull(operatorField); assertTrue(operatorField.isTextual()); if (contentsFields.asText().startsWith("Sync")) { assertEquals(1, parallelismField.asInt()); } else { assertEquals(expectedParallelism, parallelismField.asInt()); } idToNode.put(vertexIdField.asText(), vertex); } assertEquals(numNodes, idToNode.size()); // check that all inputs are contained for (JsonNode node : idToNode.values()) { JsonNode inputsField = node.get("inputs"); if (inputsField != null) { Iterator<JsonNode> inputsIter = inputsField.elements(); while (inputsIter.hasNext()) { JsonNode inputNode = inputsIter.next(); JsonNode inputIdField = inputNode.get("id"); assertNotNull(inputIdField); assertTrue(inputIdField.isTextual()); String inputIdString = inputIdField.asText(); assertTrue(idToNode.containsKey(inputIdString)); } } } }
Example 14
Source File: JsonJobGraphGenerationTest.java From flink with Apache License 2.0 | 4 votes |
@Override public void validateJson(String json) throws Exception { final Map<String, JsonNode> idToNode = new HashMap<>(); // validate the produced JSON ObjectMapper m = new ObjectMapper(); JsonNode rootNode = m.readTree(json); JsonNode idField = rootNode.get("jid"); JsonNode nameField = rootNode.get("name"); JsonNode arrayField = rootNode.get("nodes"); assertNotNull(idField); assertNotNull(nameField); assertNotNull(arrayField); assertTrue(idField.isTextual()); assertTrue(nameField.isTextual()); assertTrue(arrayField.isArray()); ArrayNode array = (ArrayNode) arrayField; Iterator<JsonNode> iter = array.elements(); while (iter.hasNext()) { JsonNode vertex = iter.next(); JsonNode vertexIdField = vertex.get("id"); JsonNode parallelismField = vertex.get("parallelism"); JsonNode contentsFields = vertex.get("description"); JsonNode operatorField = vertex.get("operator"); assertNotNull(vertexIdField); assertTrue(vertexIdField.isTextual()); assertNotNull(parallelismField); assertTrue(parallelismField.isNumber()); assertNotNull(contentsFields); assertTrue(contentsFields.isTextual()); assertNotNull(operatorField); assertTrue(operatorField.isTextual()); if (contentsFields.asText().startsWith("Sync")) { assertEquals(1, parallelismField.asInt()); } else { assertEquals(expectedParallelism, parallelismField.asInt()); } idToNode.put(vertexIdField.asText(), vertex); } assertEquals(numNodes, idToNode.size()); // check that all inputs are contained for (JsonNode node : idToNode.values()) { JsonNode inputsField = node.get("inputs"); if (inputsField != null) { Iterator<JsonNode> inputsIter = inputsField.elements(); while (inputsIter.hasNext()) { JsonNode inputNode = inputsIter.next(); JsonNode inputIdField = inputNode.get("id"); assertNotNull(inputIdField); assertTrue(inputIdField.isTextual()); String inputIdString = inputIdField.asText(); assertTrue(idToNode.containsKey(inputIdString)); } } } }