热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode类的使用及代码示例

本文整理了Java中org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode类的一些代码示例,展示了JsonNo

本文整理了Java中org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode类的一些代码示例,展示了JsonNode类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode类的具体详情如下:
包路径:org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode
类名称:JsonNode

JsonNode介绍

暂无

代码示例

代码示例来源:origin: apache/flink

/**
* Select the language from the incoming JSON text.
*/
@Override
public void flatMap(String value, Collector> out) throws Exception {
if (jsOnParser== null) {
jsOnParser= new ObjectMapper();
}
JsonNode jsOnNode= jsonParser.readValue(value, JsonNode.class);
boolean isEnglish = jsonNode.has("user") && jsonNode.get("user").has("lang") && jsonNode.get("user").get("lang").asText().equals("en");
boolean hasText = jsonNode.has("text");
if (isEnglish && hasText) {
// message of tweet
StringTokenizer tokenizer = new StringTokenizer(jsonNode.get("text").asText());
// split the message
while (tokenizer.hasMoreTokens()) {
String result = tokenizer.nextToken().replaceAll("\\s*", "").toLowerCase();
if (!result.equals("")) {
out.collect(new Tuple2<>(result, 1));
}
}
}
}
}

代码示例来源:origin: apache/flink

JsonNode idField = rootNode.get("jid");
JsonNode nameField = rootNode.get("name");
JsonNode arrayField = rootNode.get("nodes");
assertTrue(idField.isTextual());
assertTrue(nameField.isTextual());
assertTrue(arrayField.isArray());
JsonNode vertexIdField = vertex.get("id");
JsonNode parallelismField = vertex.get("parallelism");
JsonNode cOntentsFields= vertex.get("description");
JsonNode operatorField = vertex.get("operator");
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());
assertEquals(expectedParallelism, parallelismField.asInt());
idToNode.put(vertexIdField.asText(), vertex);
JsonNode inputsField = node.get("inputs");

代码示例来源:origin: apache/flink

private Object convertByteArray(JsonNode node) {
try {
return node.binaryValue();
} catch (IOException e) {
throw new RuntimeException("Unable to deserialize byte array.", e);
}
}
}

代码示例来源:origin: apache/flink

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
}
}

代码示例来源:origin: apache/flink

private Object convertObjectArray(JsonNode node, TypeInformation elementType) {
final Object[] array = (Object[]) Array.newInstance(elementType.getTypeClass(), node.size());
for (int i = 0; i array[i] = convert(node.get(i), elementType);
}
return array;
}

代码示例来源:origin: apache/flink

private static TypeInformation[] convertTypes(String location, JsonNode arrayNode, JsonNode root) {
final TypeInformation[] types = new TypeInformation[arrayNode.size()];
final Iterator elements = arrayNode.elements();
int i = 0;
while (elements.hasNext()) {
final TypeInformation elementType = convertType(
location + '[' + i + ']',
elements.next(),
root);
types[i] = elementType;
i += 1;
}
return types;
}
}

代码示例来源:origin: apache/flink

@Test
public void getTaskManagerLogAndStdoutFiles() {
try {
String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/");
ObjectMapper mapper = new ObjectMapper();
JsonNode parsed = mapper.readTree(json);
ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers");
JsonNode taskManager = taskManagers.get(0);
String id = taskManager.get("id").asText();
WebMonitorUtils.LogFileLocation logFiles = WebMonitorUtils.LogFileLocation.find(CLUSTER_CONFIGURATION);
//we check for job manager log files, since no separate taskmanager logs exist
FileUtils.writeStringToFile(logFiles.logFile, "job manager log");
String logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/" + id + "/log");
assertTrue(logs.contains("job manager log"));
FileUtils.writeStringToFile(logFiles.stdOutFile, "job manager out");
logs = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/" + id + "/stdout");
assertTrue(logs.contains("job manager out"));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

代码示例来源:origin: apache/flink

if (node.has(REF) && node.get(REF).isTextual()) {
ref = Optional.of(resolveReference(node.get(REF).asText(), node, root));
} else {
ref = Optional.empty();
if (node.has(TYPE)) {
final JsonNode typeNode = node.get(TYPE);
if (typeNode.isArray()) {
final Iterator elements = typeNode.elements();
while (elements.hasNext()) {
types.add(elements.next().asText());
else if (typeNode.isTextual()) {
types.add(typeNode.asText());
break;
case TYPE_STRING:
if (node.has(FORMAT)) {
typeSet.add(convertStringFormat(location, node.get(FORMAT)));
} else if (node.has(CONTENT_ENCODING)) {
typeSet.add(convertStringEncoding(location, node.get(CONTENT_ENCODING)));
} else {
typeSet.add(Types.STRING);
default:
throw new IllegalArgumentException(
"Unsupported type '" + node.get(TYPE).asText() + "' in node: " + location);

代码示例来源:origin: apache/flink

private static String convertLegacyJobOverview(String legacyOverview) throws IOException {
JsonNode root = mapper.readTree(legacyOverview);
JsonNode finishedJobs = root.get("finished");
JsonNode job = finishedJobs.get(0);
JobID jobId = JobID.fromHexString(job.get("jid").asText());
String name = job.get("name").asText();
JobStatus state = JobStatus.valueOf(job.get("state").asText());
long startTime = job.get("start-time").asLong();
long endTime = job.get("end-time").asLong();
long duration = job.get("duration").asLong();
long lastMod = job.get("last-modification").asLong();
JsonNode tasks = job.get("tasks");
int numTasks = tasks.get("total").asInt();
int pending = tasks.get("pending").asInt();
int running = tasks.get("running").asInt();
int finished = tasks.get("finished").asInt();
int canceling = tasks.get("canceling").asInt();
int canceled = tasks.get("canceled").asInt();
int failed = tasks.get("failed").asInt();

代码示例来源:origin: apache/flink

private static TypeInformation 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> fieldIter = props.fields();
int i = 0;
while (fieldIter.hasNext()) {
final Map.Entry 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);
}

代码示例来源:origin: apache/flink

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);
}

代码示例来源:origin: apache/flink

@Test
public void testDeserializeWithMetadata() throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode initialKey = mapper.createObjectNode();
initialKey.put("index", 4);
byte[] serializedKey = mapper.writeValueAsBytes(initialKey);
ObjectNode initialValue = mapper.createObjectNode();
initialValue.put("word", "world");
byte[] serializedValue = mapper.writeValueAsBytes(initialValue);
JSONKeyValueDeserializationSchema schema = new JSONKeyValueDeserializationSchema(true);
ObjectNode deserializedValue = schema.deserialize(serializedKey, serializedValue, "topic#1", 3, 4);
Assert.assertEquals(4, deserializedValue.get("key").get("index").asInt());
Assert.assertEquals("world", deserializedValue.get("value").get("word").asText());
Assert.assertEquals("topic#1", deserializedValue.get("metadata").get("topic").asText());
Assert.assertEquals(4, deserializedValue.get("metadata").get("offset").asInt());
Assert.assertEquals(3, deserializedValue.get("metadata").get("partition").asInt());
}
}

代码示例来源:origin: org.apache.flink/flink-runtime

@Override
public JobDetails deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
JsonNode rootNode = jsonParser.readValueAsTree();
JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).textValue());
String jobName = rootNode.get(FIELD_NAME_JOB_NAME).textValue();
long startTime = rootNode.get(FIELD_NAME_START_TIME).longValue();
long endTime = rootNode.get(FIELD_NAME_END_TIME).longValue();
long duration = rootNode.get(FIELD_NAME_DURATION).longValue();
JobStatus jobStatus = JobStatus.valueOf(rootNode.get(FIELD_NAME_STATUS).textValue());
long lastUpdateTime = rootNode.get(FIELD_NAME_LAST_MODIFICATION).longValue();
JsonNode tasksNode = rootNode.get("tasks");
int numTasks = tasksNode.get(FIELD_NAME_TOTAL_NUMBER_TASKS).intValue();
int[] numVerticesPerExecutiOnState= new int[ExecutionState.values().length];
for (ExecutionState executionState : ExecutionState.values()) {
numVerticesPerExecutionState[executionState.ordinal()] = tasksNode.get(executionState.name().toLowerCase()).intValue();
}
return new JobDetails(
jobId,
jobName,
startTime,
endTime,
duration,
jobStatus,
lastUpdateTime,
numVerticesPerExecutionState,
numTasks);
}
}

代码示例来源:origin: apache/flink

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) {
final String time = node.asText();
if (time.indexOf('Z') <0 || time.indexOf('.') >= 0) {
throw new IllegalStateException(
final String timestamp = node.asText();
if (timestamp.indexOf('Z') <0) {
throw new IllegalStateException(

代码示例来源:origin: com.alibaba.blink/flink-runtime

@Override
public SerializedThrowable deserialize(
final JsonParser p,
final DeserializationContext ctxt) throws IOException {
final JsonNode root = p.readValueAsTree();
final byte[] serializedException = root.get(FIELD_NAME_SERIALIZED_THROWABLE).binaryValue();
try {
return InstantiationUtil.deserializeObject(serializedException, ClassLoader.getSystemClassLoader());
} catch (ClassNotFoundException e) {
throw new IOException("Failed to deserialize " + SerializedThrowable.class.getCanonicalName(), e);
}
}

代码示例来源:origin: apache/flink

private Row convertRow(JsonNode node, RowTypeInfo info) {
final String[] names = info.getFieldNames();
final TypeInformation[] types = info.getFieldTypes();
final Row row = new Row(names.length);
for (int i = 0; i final String name = names[i];
final JsonNode subNode = node.get(name);
if (subNode == null) {
if (failOnMissingField) {
throw new IllegalStateException(
"Could not find field with name '" + name + "'.");
} else {
row.setField(i, null);
}
} else {
row.setField(i, convert(subNode, types[i]));
}
}
return row;
}

代码示例来源:origin: apache/flink

@Test
public void getTaskmanagers() throws Exception {
String json = TestBaseUtils.getFromHTTP("http://localhost:" + getRestPort() + "/taskmanagers/");
ObjectMapper mapper = new ObjectMapper();
JsonNode parsed = mapper.readTree(json);
ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers");
assertNotNull(taskManagers);
assertEquals(NUM_TASK_MANAGERS, taskManagers.size());
JsonNode taskManager = taskManagers.get(0);
assertNotNull(taskManager);
assertEquals(NUM_SLOTS, taskManager.get("slotsNumber").asInt());
assertTrue(taskManager.get("freeSlots").asInt() <= NUM_SLOTS);
}

代码示例来源:origin: com.alibaba.blink/flink-runtime

@Override
public ResourceProfile deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
JsonNode rootNode = jsonParser.readValueAsTree();
double cpuCores = rootNode.get(FIELD_NAME_RESOURCE_CPU_CORES).doubleValue();
int heapMemoryInMB = convertByteToMegabyte(rootNode.get(FIELD_NAME_RESOURCE_HEAP_MEMORY).longValue());
int directMemoryInMB = convertByteToMegabyte(rootNode.get(FIELD_NAME_RESOURCE_DIRECT_MEMORY).longValue());
int nativeMemoryInMB = convertByteToMegabyte(rootNode.get(FIELD_NAME_RESOURCE_NATIVE_MEMORY).longValue());
int networkMemoryInMB = convertByteToMegabyte(rootNode.get(FIELD_NAME_RESOURCE_NETWORK_MEMORY).longValue());
int managedMemoryInMB = convertByteToMegabyte(rootNode.get(FIELD_NAME_RESOURCE_MANAGED_MEMORY).longValue());
Map extendedResources = new HashMap<>();
if (managedMemoryInMB != 0) {
extendedResources.put(ResourceSpec.MANAGED_MEMORY_NAME, new CommonExtendedResource(ResourceSpec.MANAGED_MEMORY_NAME, managedMemoryInMB));
}
return new ResourceProfile(
cpuCores, heapMemoryInMB, directMemoryInMB, nativeMemoryInMB, networkMemoryInMB, extendedResources);
}

代码示例来源:origin: apache/flink

@Test
public void testDeserializeWithoutKey() throws IOException {
ObjectMapper mapper = new ObjectMapper();
byte[] serializedKey = null;
ObjectNode initialValue = mapper.createObjectNode();
initialValue.put("word", "world");
byte[] serializedValue = mapper.writeValueAsBytes(initialValue);
JSONKeyValueDeserializationSchema schema = new JSONKeyValueDeserializationSchema(false);
ObjectNode deserializedValue = schema.deserialize(serializedKey, serializedValue, "", 0, 0);
Assert.assertTrue(deserializedValue.get("metadata") == null);
Assert.assertTrue(deserializedValue.get("key") == null);
Assert.assertEquals("world", deserializedValue.get("value").get("word").asText());
}

代码示例来源:origin: org.apache.flink/flink-json

if (node.has(REF) && node.get(REF).isTextual()) {
ref = Optional.of(resolveReference(node.get(REF).asText(), node, root));
} else {
ref = Optional.empty();
if (node.has(TYPE)) {
final JsonNode typeNode = node.get(TYPE);
if (typeNode.isArray()) {
final Iterator elements = typeNode.elements();
while (elements.hasNext()) {
types.add(elements.next().asText());
else if (typeNode.isTextual()) {
types.add(typeNode.asText());
break;
case TYPE_STRING:
if (node.has(FORMAT)) {
typeSet.add(convertStringFormat(location, node.get(FORMAT)));
} else if (node.has(CONTENT_ENCODING)) {
typeSet.add(convertStringEncoding(location, node.get(CONTENT_ENCODING)));
} else {
typeSet.add(Types.STRING);
default:
throw new IllegalArgumentException(
"Unsupported type '" + node.get(TYPE).asText() + "' in node: " + location);

推荐阅读
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • VScode格式化文档换行或不换行的设置方法
    本文介绍了在VScode中设置格式化文档换行或不换行的方法,包括使用插件和修改settings.json文件的内容。详细步骤为:找到settings.json文件,将其中的代码替换为指定的代码。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • 目录实现效果:实现环境实现方法一:基本思路主要代码JavaScript代码总结方法二主要代码总结方法三基本思路主要代码JavaScriptHTML总结实 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文介绍了C#中数据集DataSet对象的使用及相关方法详解,包括DataSet对象的概述、与数据关系对象的互联、Rows集合和Columns集合的组成,以及DataSet对象常用的方法之一——Merge方法的使用。通过本文的阅读,读者可以了解到DataSet对象在C#中的重要性和使用方法。 ... [详细]
  • 本文介绍了OC学习笔记中的@property和@synthesize,包括属性的定义和合成的使用方法。通过示例代码详细讲解了@property和@synthesize的作用和用法。 ... [详细]
  • 安卓select模态框样式改变_微软Office风格的多端(Web、安卓、iOS)组件库——Fabric UI...
    介绍FabricUI是微软开源的一套Office风格的多端组件库,共有三套针对性的组件,分别适用于web、android以及iOS,Fab ... [详细]
  • 本文讨论了在Spring 3.1中,数据源未能自动连接到@Configuration类的错误原因,并提供了解决方法。作者发现了错误的原因,并在代码中手动定义了PersistenceAnnotationBeanPostProcessor。作者删除了该定义后,问题得到解决。此外,作者还指出了默认的PersistenceAnnotationBeanPostProcessor的注册方式,并提供了自定义该bean定义的方法。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 1,关于死锁的理解死锁,我们可以简单的理解为是两个线程同时使用同一资源,两个线程又得不到相应的资源而造成永无相互等待的情况。 2,模拟死锁背景介绍:我们创建一个朋友 ... [详细]
author-avatar
沈婧颖_491
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有