org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode.has()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(211)

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

JsonNode.has介绍

暂无

代码示例

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

/**
   * Select the language from the incoming JSON text.
   */
  @Override
  public void flatMap(String value, Collector<Tuple2<String, Integer>> 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

if (node.has(REF) && node.get(REF).isTextual()) {
if (node.has(TYPE)) {
  final JsonNode typeNode = node.get(TYPE);
        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 {
  ref.filter(r -> r.has(TYPE)).ifPresent(r -> typeSet.add(convertType(node.get(REF).asText(), r, root)));
if (node.has(ONE_OF) && node.get(ONE_OF).isArray()) {
  final TypeInformation<?>[] types = convertTypes(location + '/' + ONE_OF, node.get(ONE_OF), root);
  typeSet.addAll(Arrays.asList(types));
else if (ref.isPresent() && ref.get().has(ONE_OF) && ref.get().get(ONE_OF).isArray()) {
  final TypeInformation<?>[] types = convertTypes(node.get(REF).asText() + '/' + ONE_OF, ref.get().get(ONE_OF), root);
  typeSet.addAll(Arrays.asList(types));
if (node.has(ALL_OF) || node.has(ANY_OF) || node.has(NOT) || node.has(EXTENDS) || node.has(DISALLOW)) {
  throw new IllegalArgumentException(
    "Union types are such as '" + ALL_OF + "', '" + ANY_OF + "' etc. " +

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

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

代码示例来源: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: com.alibaba.blink/flink-examples-streaming

/**
   * Select the language from the incoming JSON text.
   */
  @Override
  public void flatMap(String value, Collector<Tuple2<String, Integer>> 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: org.apache.flink/flink-json

if (node.has(REF) && node.get(REF).isTextual()) {
if (node.has(TYPE)) {
  final JsonNode typeNode = node.get(TYPE);
        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 {
  ref.filter(r -> r.has(TYPE)).ifPresent(r -> typeSet.add(convertType(node.get(REF).asText(), r, root)));
if (node.has(ONE_OF) && node.get(ONE_OF).isArray()) {
  final TypeInformation<?>[] types = convertTypes(location + '/' + ONE_OF, node.get(ONE_OF), root);
  typeSet.addAll(Arrays.asList(types));
else if (ref.isPresent() && ref.get().has(ONE_OF) && ref.get().get(ONE_OF).isArray()) {
  final TypeInformation<?>[] types = convertTypes(node.get(REF).asText() + '/' + ONE_OF, ref.get().get(ONE_OF), root);
  typeSet.addAll(Arrays.asList(types));
if (node.has(ALL_OF) || node.has(ANY_OF) || node.has(NOT) || node.has(EXTENDS) || node.has(DISALLOW)) {
  throw new IllegalArgumentException(
    "Union types are such as '" + ALL_OF + "', '" + ANY_OF + "' etc. " +

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

if (node.has(REF) && node.get(REF).isTextual()) {
if (node.has(TYPE)) {
  final JsonNode typeNode = node.get(TYPE);
        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 {
  ref.filter(r -> r.has(TYPE)).ifPresent(r -> typeSet.add(convertType(node.get(REF).asText(), r, root)));
if (node.has(ONE_OF) && node.get(ONE_OF).isArray()) {
  final TypeInformation<?>[] types = convertTypes(location + '/' + ONE_OF, node.get(ONE_OF), root);
  typeSet.addAll(Arrays.asList(types));
else if (ref.isPresent() && ref.get().has(ONE_OF) && ref.get().get(ONE_OF).isArray()) {
  final TypeInformation<?>[] types = convertTypes(node.get(REF).asText() + '/' + ONE_OF, ref.get().get(ONE_OF), root);
  typeSet.addAll(Arrays.asList(types));
if (node.has(ALL_OF) || node.has(ANY_OF) || node.has(NOT) || node.has(EXTENDS) || node.has(DISALLOW)) {
  throw new IllegalArgumentException(
    "Union types are such as '" + ALL_OF + "', '" + ANY_OF + "' etc. " +

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

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

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

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

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

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: com.alibaba.blink/flink-json

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: com.alibaba.blink/flink-runtime

@Override
  public JobConfigInfo deserialize(
      JsonParser jsonParser,
      DeserializationContext deserializationContext) throws IOException {
    JsonNode rootNode = jsonParser.readValueAsTree();
    final JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).asText());
    final String jobName = rootNode.get(FIELD_NAME_JOB_NAME).asText();
    final ExecutionConfigInfo executionConfigInfo;
    if (rootNode.has(FIELD_NAME_EXECUTION_CONFIG)) {
      executionConfigInfo = RestMapperUtils.getStrictObjectMapper().treeToValue(rootNode.get(FIELD_NAME_EXECUTION_CONFIG), ExecutionConfigInfo.class);
    } else {
      executionConfigInfo = null;
    }
    return new JobConfigInfo(jobId, jobName, executionConfigInfo);
  }
}

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

@Override
  public JobConfigInfo deserialize(
      JsonParser jsonParser,
      DeserializationContext deserializationContext) throws IOException {
    JsonNode rootNode = jsonParser.readValueAsTree();
    final JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).asText());
    final String jobName = rootNode.get(FIELD_NAME_JOB_NAME).asText();
    final ExecutionConfigInfo executionConfigInfo;
    if (rootNode.has(FIELD_NAME_EXECUTION_CONFIG)) {
      executionConfigInfo = RestMapperUtils.getStrictObjectMapper().treeToValue(rootNode.get(FIELD_NAME_EXECUTION_CONFIG), ExecutionConfigInfo.class);
    } else {
      executionConfigInfo = null;
    }
    return new JobConfigInfo(jobId, jobName, executionConfigInfo);
  }
}

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

@Override
  public JobConfigInfo deserialize(
      JsonParser jsonParser,
      DeserializationContext deserializationContext) throws IOException {
    JsonNode rootNode = jsonParser.readValueAsTree();
    final JobID jobId = JobID.fromHexString(rootNode.get(FIELD_NAME_JOB_ID).asText());
    final String jobName = rootNode.get(FIELD_NAME_JOB_NAME).asText();
    final ExecutionConfigInfo executionConfigInfo;
    if (rootNode.has(FIELD_NAME_EXECUTION_CONFIG)) {
      executionConfigInfo = RestMapperUtils.getStrictObjectMapper().treeToValue(rootNode.get(FIELD_NAME_EXECUTION_CONFIG), ExecutionConfigInfo.class);
    } else {
      executionConfigInfo = null;
    }
    return new JobConfigInfo(jobId, jobName, executionConfigInfo);
  }
}

相关文章