gpt4 book ai didi

com.fasterxml.jackson.dataformat.yaml.YAMLMapper.readValue()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-17 08:06:40 28 4
gpt4 key购买 nike

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

YAMLMapper.readValue介绍

暂无

代码示例

代码示例来源:origin: com.github.duanxinyuan/library-json-jackson

/**
 * 反序列化Yaml文件
 * @param path 文件路径
 */
public static <V> V fromYamlFile(String path, Class<V> c) {
  try {
    return yamlMapper.readValue(new File(path), c);
  } catch (IOException e) {
    log.error("jackson from yaml error, path: {}, type: {}", path, c, e);
    return null;
  }
}

代码示例来源:origin: com.github.duanxinyuan/library-json-jackson

/**
 * 反序列化Yaml文件
 * @param path 文件路径
 */
public static <V> V fromYamlFile(String path, TypeReference<V> type) {
  try {
    return yamlMapper.readValue(new File(path), type);
  } catch (IOException e) {
    log.error("jackson from yaml error, path: {}, type: {}", path, type, e);
    return null;
  }
}

代码示例来源:origin: org.seedstack.seed/seed-core

@Override
  public Map<String, Object> collect() {
    Map<String, Object> result = new HashMap<>();
    result.put("version", seedVersion == null ? "UNKNOWN" : seedVersion);
    result.put("businessVersion", businessVersion == null ? "UNKNOWN" : businessVersion);
    result.put("inconsistentPlugins", inconsistentPlugins);
    result.put("contextClass", context == null ? "NONE" : context.getClass().getName());
    try {
      result.put("configuration", yamlMapper.readValue(configuration.toString(), Map.class));
    } catch (IOException | RuntimeException e) {
      result.put("rawConfiguration", configuration.toString());
    }
    return result;
  }
}

代码示例来源:origin: com.github.cafdataprocessing/worker-document-testing-unit

/**
 * Configures a new Document using a file with JSON or YAML-serialized Document Worker task
 *
 * @param path File path
 * @return current Document builder
 * @throws IOException An issue with accessing a file
 */
public static DocumentBuilder fromFile(final String path) throws IOException
{
  final YAMLMapper mapper = new YAMLMapper();
  final byte[] bytes = FileUtils.readFileToByteArray(new File(path));
  final DocumentWorkerDocumentTask workerTask = mapper.readValue(bytes, DocumentWorkerDocumentTask.class);
  return new DocumentBuilder(workerTask);
}

代码示例来源:origin: com.github.duanxinyuan/library-json-jackson

/**
 * 反序列化Recources目录下的Yaml文件
 * @param name 文件名
 */
public static <V> V fromYamlRecource(String name, Class<V> c) {
  try (InputStream inputStream = getResourceStream(name); InputStreamReader reader = getResourceReader(inputStream)) {
    if (reader == null) {
      return null;
    }
    return yamlMapper.readValue(reader, c);
  } catch (IOException e) {
    log.error("jackson from yaml recource error, name: {}, type: {}", name, c, e);
    return null;
  }
}

代码示例来源:origin: com.github.duanxinyuan/library-json-jackson

/**
 * 反序列化Recources目录下的Yaml文件
 * @param name 文件名
 */
public static <V> V fromYamlRecource(String name, TypeReference<V> type) {
  try (InputStream inputStream = getResourceStream(name); InputStreamReader reader = getResourceReader(inputStream)) {
    if (reader == null) {
      return null;
    }
    return yamlMapper.readValue(reader, type);
  } catch (IOException e) {
    log.error("jackson from yaml recource error, name: {}, type: {}", name, type, e);
    return null;
  }
}

代码示例来源:origin: me.snowdrop/istio-common

Object deserialize(JsonNode node, String fieldName, Class targetClass, DeserializationContext ctxt) throws IOException {
    final String type = getFieldClassFQN(targetClass, valueType);
    try {
      // load class of the field
      final Class<?> fieldClass = Thread.currentThread().getContextClassLoader().loadClass(type);
      // create a map type matching the type of the field from the mapping information
      final YAMLMapper codec = (YAMLMapper) ctxt.getParser().getCodec();
      MapType mapType = codec.getTypeFactory().constructMapType(Map.class, String.class, fieldClass);
      // get a parser taking the current value as root
      final JsonParser traverse = node.get(fieldName).traverse(codec);
      // and use it to deserialize the subtree as the map type we just created
      return codec.readValue(traverse, mapType);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Unsupported type '" + type + "' for field '" + fieldName +
          "' on '" + targetClass.getName() + "' class. Full type was " + this, e);
    }
  }
}

代码示例来源:origin: me.snowdrop/istio-model

document = document.trim();
if (!document.isEmpty()) {
  final Map<String, Object> resourceYaml = objectMapper.readValue(document, Map.class);

代码示例来源:origin: snowdrop/istio-java-api

Object deserialize(JsonNode node, String fieldName, Class targetClass, DeserializationContext ctxt) throws IOException {
    final String type = getFieldClassFQN(targetClass, valueType);
    try {
      // load class of the field
      final Class<?> fieldClass = Thread.currentThread().getContextClassLoader().loadClass(type);
      // create a map type matching the type of the field from the mapping information
      final YAMLMapper codec = (YAMLMapper) ctxt.getParser().getCodec();
      MapType mapType = codec.getTypeFactory().constructMapType(Map.class, String.class, fieldClass);
      // get a parser taking the current value as root
      final JsonParser traverse = node.get(fieldName).traverse(codec);
      // and use it to deserialize the subtree as the map type we just created
      return codec.readValue(traverse, mapType);
    } catch (ClassNotFoundException e) {
      throw new RuntimeException("Unsupported type '" + type + "' for field '" + fieldName +
          "' on '" + targetClass.getName() + "' class. Full type was " + this, e);
    }
  }
}

代码示例来源:origin: snowdrop/istio-java-api

document = document.trim();
if (!document.isEmpty()) {
  final Map<String, Object> resourceYaml = objectMapper.readValue(document, Map.class);

代码示例来源:origin: io.takari.orchestra.plugins/yaml

@Override
public Collection<ProcessDefinition> parse(InputStream in) throws ParserException {
  YAMLMapper m = new YAMLMapper();
  Map<String, Object> data;
  try {
    data = m.readValue(in, Map.class);
  } catch (IOException e) {
    throw new ParserException("Error while parsing the data", e);
  }
  log.debug("parse -> got: {}", data);
  Collection<ProcessDefinition> result = new ArrayList<>();
  for (Map.Entry<String, Object> entry : data.entrySet()) {
    String id = entry.getKey();
    Object v = entry.getValue();
    if (!(v instanceof List)) {
      throw new ParserException("Unsupported element type in the process '" + id + "': " + v);
    }
    List<Object> l = (List<Object>) v;
    IdGenerator idGenerator = new IdGenerator();
    ProcessDefinition pd = new ProcessDefinition(id, addEntryPoint(idGenerator, toElements(idGenerator, l)),
        Collections.singletonMap(ProcessDefinition.SOURCE_TYPE_ATTRIBUTE, TYPE));
    if (log.isDebugEnabled()) {
      print(pd, 0);
    }
    result.add(pd);
  }
  return result;
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com