org.yaml.snakeyaml.representer.Representer类的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(1601)

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

Representer介绍

[英]Represent JavaBeans
[中]表示JavaBeans

代码示例

代码示例来源:origin: embulk/embulk

private Yaml newYaml() {
    return new Yaml(new SafeConstructor(), new Representer(), new DumperOptions(), new YamlTagResolver());
  }
}

代码示例来源:origin: apache/incubator-shardingsphere

@Override
protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property, final Object propertyValue, final Tag customTag) {
  NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
  return isUnwantedNodeTuple(tuple.getValueNode()) ? null : tuple;
}

代码示例来源:origin: redisson/redisson

public TypeDescription addTypeDescription(TypeDescription td) {
  if (Collections.EMPTY_MAP == typeDefinitions) {
    typeDefinitions = new HashMap<Class<? extends Object>, TypeDescription>();
  }
  if (td.getTag() != null) {
    addClassTag(td.getType(), td.getTag());
  }
  td.setPropertyUtils(getPropertyUtils());
  return typeDefinitions.put(td.getType(), td);
}

代码示例来源:origin: redisson/redisson

private static DumperOptions initDumperOptions(Representer representer) {
  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setDefaultFlowStyle(representer.getDefaultFlowStyle());
  dumperOptions.setDefaultScalarStyle(representer.getDefaultScalarStyle());
  dumperOptions.setAllowReadOnlyProperties(representer.getPropertyUtils().isAllowReadOnlyProperties());
  dumperOptions.setTimeZone(representer.getTimeZone());
  return dumperOptions;
}

代码示例来源:origin: redisson/redisson

FlowStyle oldStyle = representer.getDefaultFlowStyle();
if (flowStyle != null) {
  representer.setDefaultFlowStyle(flowStyle);
dumpAll(list.iterator(), buffer, rootTag);
representer.setDefaultFlowStyle(oldStyle);
return buffer.toString();

代码示例来源:origin: kamax-matrix/mxisd

public static MxisdConfig loadFromFile(String path) throws IOException {
  Representer rep = new Representer();
  rep.getPropertyUtils().setAllowReadOnlyProperties(true);
  rep.getPropertyUtils().setSkipMissingProperties(true);
  Yaml yaml = new Yaml(new Constructor(MxisdConfig.class), rep);
  try (FileInputStream is = new FileInputStream(path)) {
    Object o = yaml.load(is);
    return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), MxisdConfig.class);
  }
}

代码示例来源:origin: com.atlassian.tenant/atlassian-tenant-context-impl

@SuppressWarnings("unchecked")
  private static Map<String, String> parseYamlStream(InputStream tenantStream) {
    Yaml yaml = new Yaml(new Constructor(), new Representer(), new DumperOptions(),
        new Resolver() {
          @Override
          protected void addImplicitResolvers() { } // forces all yaml values to be parsed as Strings
        }
    );
    return (Map<String, String>) yaml.load(tenantStream);
  }
}

代码示例来源:origin: EngineHub/WorldEdit

public YAMLProcessor(File file, boolean writeDefaults, YAMLFormat format) {
  super(new LinkedHashMap<>(), writeDefaults);
  this.format = format;
  DumperOptions options = new DumperOptions();
  options.setIndent(4);
  options.setDefaultFlowStyle(format.getStyle());
  Representer representer = new FancyRepresenter();
  representer.setDefaultFlowStyle(format.getStyle());
  yaml = new Yaml(new SafeConstructor(), representer, options);
  this.file = file;
}

代码示例来源:origin: com.netflix.spinnaker.halyard/halyard-config

@Bean
Yaml yamlParser() {
 DumperOptions options = new DumperOptions();
 options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
 options.setDefaultScalarStyle(DumperOptions.ScalarStyle.PLAIN);
 return new Yaml(new SafeConstructor(), new Representer(), options);
}

代码示例来源:origin: airbnb/okreplay

private static Yaml getYaml() {
  Representer representer = new TapeRepresenter();
  representer.addClassTag(YamlTape.class, YamlTape.TAPE_TAG);
  Constructor constructor = new TapeConstructor();
  constructor.addTypeDescription(new TypeDescription(YamlTape.class, YamlTape.TAPE_TAG));
  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setDefaultFlowStyle(BLOCK);
  dumperOptions.setWidth(256);
  Yaml yaml = new Yaml(constructor, representer, dumperOptions);
  yaml.setBeanAccess(BeanAccess.FIELD);
  return yaml;
 }
}

代码示例来源:origin: rancher/cattle

private String convertToYml(Map<String, Object> dockerComposeData) {
  DumperOptions options = new DumperOptions();
  options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
  options.setLineBreak(LineBreak.WIN);
  Representer representer = new SkipNullRepresenter();
  representer.addClassTag(LBConfigMetadataStyle.class, Tag.MAP);
  
  Yaml yaml = new Yaml(representer, options);
  String yamlStr = yaml.dump(dockerComposeData);
  return yamlStr.replaceAll("[$]", "\\$\\$");
}

代码示例来源:origin: MylesIsCool/ViaVersion

@Override
  protected Yaml initialValue() {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
    options.setPrettyFlow(false);
    options.setIndent(2);
    return new Yaml(new YamlConstructor(), new Representer(), options);
  }
};

代码示例来源:origin: dyc87112/spring-cloud-config-admin

protected Yaml buildYaml() {
  Constructor constructor = new Constructor();
  Representer representer = new Representer();
  representer.setDefaultFlowStyle(FlowStyle.BLOCK);
  representer.setDefaultScalarStyle(ScalarStyle.PLAIN);
  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setAllowReadOnlyProperties(true);
  dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
  dumperOptions.setDefaultScalarStyle(ScalarStyle.PLAIN);
  dumperOptions.setLineBreak(this.getLineBreak());
  LimitedResolver limitedResolver = new LimitedResolver();
  return new Yaml(constructor, representer, dumperOptions, limitedResolver);
}

代码示例来源:origin: cereda/arara

Representer representer = new Representer();
representer.addClassTag(Rule.class, new Tag("!config"));
Yaml yaml = new Yaml(new Constructor(Rule.class), representer);
Rule rule = null;
try {
  rule = yaml.loadAs(new FileReader(file), Rule.class);
} catch (MarkedYAMLException yamlException) {
  throw new AraraException(

代码示例来源:origin: com.openshift/openshift-restclient-java

public IKubeClientConfig loadKubeClientConfig(Reader reader) {
  Representer representer = new Representer();
  Yaml parser = new Yaml(new KubeClientConfigConstructor(new YamlPropertyUtils()), representer);
  representer.getPropertyUtils().setSkipMissingProperties(true);
  return parser.loadAs(reader, KubeClientConfig.class);
}

代码示例来源:origin: rundeck/rundeck-cli

private static void configYamlFormat(final ToolBelt belt, final RdClientConfig config) {
  DumperOptions dumperOptions = new DumperOptions();
  dumperOptions.setDefaultFlowStyle(
      "BLOCK".equalsIgnoreCase(config.getString("RD_YAML_FLOW", "BLOCK")) ?
      DumperOptions.FlowStyle.BLOCK :
      DumperOptions.FlowStyle.FLOW
  );
  dumperOptions.setPrettyFlow(config.getBool("RD_YAML_PRETTY", true));
  Representer representer = new Representer();
  representer.addClassTag(JobItem.class, Tag.MAP);
  representer.addClassTag(ScheduledJobItem.class, Tag.MAP);
  representer.addClassTag(DateInfo.class, Tag.MAP);
  representer.addClassTag(Execution.class, Tag.MAP);
  belt.formatter(new YamlFormatter(DataOutputAsFormatable, new Yaml(representer, dumperOptions)));
  belt.channels().infoEnabled(false);
  belt.channels().warningEnabled(false);
  belt.channels().errorEnabled(false);
}

代码示例来源:origin: com.hotels/shunting-yard-replicator

public static Yaml newYaml() {
 PropertyUtils propertyUtils = new AdvancedPropertyUtils();
 propertyUtils.setSkipMissingProperties(true);
 propertyUtils.setAllowReadOnlyProperties(false);
 Constructor constructor = new Constructor();
 Representer representer = new AdvancedRepresenter();
 representer.setPropertyUtils(propertyUtils);
 representer.addClassTag(CircusTrainConfig.class, Tag.MAP);
 DumperOptions dumperOptions = new DumperOptions();
 dumperOptions.setIndent(2);
 dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
 dumperOptions.setAllowReadOnlyProperties(true);
 return new Yaml(constructor, representer, dumperOptions);
}

代码示例来源:origin: org.qsardb.cargo/bodo

public void storeBodoDescriptor(BODODescriptor bodoDescriptor) throws IOException {
  Representer representer = new Representer();
  representer.setPropertyUtils(new PropertyOrderingUtils());
  Yaml yaml = new Yaml(representer);
  storeString(yaml.dump(bodoDescriptor));
}

代码示例来源:origin: microbean/microbean-helm

/**
 * Creates and returns a new {@link Yaml} instance for (optional)
 * use in writing {@link ConfigOrBuilder} and {@link
 * MetadataOrBuilder} objects.
 *
 * <p>This method never returns {@code null}.</p>
 *
 * <p>Overrides of this method must not return {@code null}.</p>
 *
 * <p>Behavior is undefined if overrides of this method interact
 * with other methods defined by this class.</p>
 *
 * @return a non-{@code null} {@link Yaml} instance
 */
protected Yaml createYaml() {
 final Representer representer = new TerseRepresenter();
 representer.setPropertyUtils(new CustomPropertyUtils());
 final DumperOptions options = new DumperOptions();
 options.setAllowReadOnlyProperties(true);
 return new Yaml(new SafeConstructor(), representer, options);
}

代码示例来源:origin: etsy/arbiter

public YamlReader(Constructor rootConstructor) {
  Representer representer = new Representer();
  representer.getPropertyUtils().setSkipMissingProperties(true);
  yamlParser = new Yaml(rootConstructor, representer, new DumperOptions(), new CustomResolver());
}

相关文章