本文整理了Java中org.yaml.snakeyaml.constructor.Constructor.addTypeDescription()
方法的一些代码示例,展示了Constructor.addTypeDescription()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Constructor.addTypeDescription()
方法的具体详情如下:
包路径:org.yaml.snakeyaml.constructor.Constructor
类名称:Constructor
方法名:addTypeDescription
[英]Make YAML aware how to parse a custom Class. If there is no root Class assigned in constructor then the 'root' property of this definition is respected.
[中]让YAML知道如何解析自定义类。如果构造函数中没有分配根类,则此定义的“根”属性将得到尊重。
代码示例来源:origin: apache/incubator-dubbo
private static <T> T parseObject(String rawConfig) {
Constructor constructor = new Constructor(ConfiguratorConfig.class);
TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class);
itemDescription.addPropertyParameters("items", ConfigItem.class);
constructor.addTypeDescription(itemDescription);
Yaml yaml = new Yaml(constructor);
return yaml.load(rawConfig);
}
代码示例来源:origin: apache/incubator-dubbo
private static <T> T parseObject(String rawConfig) {
Constructor constructor = new Constructor(ConfiguratorConfig.class);
TypeDescription itemDescription = new TypeDescription(ConfiguratorConfig.class);
itemDescription.addPropertyParameters("items", ConfigItem.class);
constructor.addTypeDescription(itemDescription);
Yaml yaml = new Yaml(constructor);
return yaml.load(rawConfig);
}
代码示例来源:origin: redisson/redisson
public Constructor(TypeDescription theRoot, Collection<TypeDescription> moreTDs) {
if (theRoot == null) {
throw new NullPointerException("Root type must be provided.");
}
this.yamlConstructors.put(null, new ConstructYamlObject());
if (!Object.class.equals(theRoot.getType())) {
rootTag = new Tag(theRoot.getType());
}
yamlClassConstructors.put(NodeId.scalar, new ConstructScalar());
yamlClassConstructors.put(NodeId.mapping, new ConstructMapping());
yamlClassConstructors.put(NodeId.sequence, new ConstructSequence());
addTypeDescription(theRoot);
if (moreTDs != null) {
for (TypeDescription td : moreTDs) {
addTypeDescription(td);
}
}
}
代码示例来源:origin: lealone/Lealone
protected void addTypeDescription(Constructor configConstructor) {
TypeDescription mapPropertyTypeDesc = new TypeDescription(MapPropertyTypeDef.class);
mapPropertyTypeDesc.putMapPropertyType("parameters", String.class, String.class);
configConstructor.addTypeDescription(mapPropertyTypeDesc);
}
代码示例来源:origin: apache/incubator-dubbo
public static TagRouterRule parse(String rawRule) {
Constructor constructor = new Constructor(TagRouterRule.class);
TypeDescription tagDescription = new TypeDescription(TagRouterRule.class);
tagDescription.addPropertyParameters("tags", Tag.class);
constructor.addTypeDescription(tagDescription);
Yaml yaml = new Yaml(constructor);
TagRouterRule rule = yaml.load(rawRule);
rule.setRawRule(rawRule);
if (CollectionUtils.isEmpty(rule.getTags())) {
rule.setValid(false);
}
rule.init();
return rule;
}
}
代码示例来源:origin: apache/incubator-dubbo
public static TagRouterRule parse(String rawRule) {
Constructor constructor = new Constructor(TagRouterRule.class);
TypeDescription tagDescription = new TypeDescription(TagRouterRule.class);
tagDescription.addPropertyParameters("tags", Tag.class);
constructor.addTypeDescription(tagDescription);
Yaml yaml = new Yaml(constructor);
TagRouterRule rule = yaml.load(rawRule);
rule.setRawRule(rawRule);
if (CollectionUtils.isEmpty(rule.getTags())) {
rule.setValid(false);
}
rule.init();
return rule;
}
}
代码示例来源:origin: apache/storm
private static Yaml yaml() {
TypeDescription topologyDescription = new TypeDescription(TopologyDef.class);
topologyDescription.putListPropertyType("spouts", SpoutDef.class);
topologyDescription.putListPropertyType("bolts", BoltDef.class);
topologyDescription.putListPropertyType("includes", IncludeDef.class);
Constructor constructor = new Constructor(TopologyDef.class);
constructor.addTypeDescription(topologyDescription);
Yaml yaml = new Yaml(constructor);
return yaml;
}
代码示例来源:origin: org.testng/testng
suiteDescription.putListPropertyType("tests", XmlTest.class);
suiteDescription.putListPropertyType("method-selectors", XmlMethodSelector.class);
constructor.addTypeDescription(suiteDescription);
testDescription.putMapPropertyType("metaGroups", String.class, List.class);
testDescription.putListPropertyType("method-selectors", XmlMethodSelector.class);
constructor.addTypeDescription(testDescription);
代码示例来源:origin: cbeust/testng
suiteDescription.addPropertyParameters("tests", XmlTest.class);
suiteDescription.addPropertyParameters("method-selectors", XmlMethodSelector.class);
constructor.addTypeDescription(suiteDescription);
testDescription.addPropertyParameters("metaGroups", String.class, List.class);
testDescription.addPropertyParameters("method-selectors", XmlMethodSelector.class);
constructor.addTypeDescription(testDescription);
代码示例来源:origin: rakam-io/rakam
public RecipeConfigParser() {
Constructor constructor = new Constructor(Recipe.class);
TypeDescription carDescription = new TypeDescription(Recipe.class);
constructor.addTypeDescription(carDescription);
Yaml yaml = new Yaml(constructor);
Recipe recipe = (Recipe) yaml.load("ecommerce_test.yml");
}
代码示例来源:origin: apache/tinkerpop
/**
* Read configuration from a file into a new {@link Settings} object.
*
* @param stream an input stream containing a Gremlin Server YAML configuration
*/
public static Settings read(final InputStream stream) {
Objects.requireNonNull(stream);
final Constructor constructor = new Constructor(Settings.class);
final TypeDescription settingsDescription = new TypeDescription(Settings.class);
settingsDescription.putListPropertyType("hosts", String.class);
settingsDescription.putListPropertyType("serializers", SerializerSettings.class);
constructor.addTypeDescription(settingsDescription);
final Yaml yaml = new Yaml(constructor);
return yaml.loadAs(stream, Settings.class);
}
代码示例来源:origin: apache/tinkerpop
settingsDescription.putListPropertyType("plugins", String.class);
settingsDescription.putListPropertyType("processors", ProcessorSettings.class);
constructor.addTypeDescription(settingsDescription);
constructor.addTypeDescription(serializerSettingsDescription);
scriptEngineSettingsDescription.putMapPropertyType("config", String.class, Object.class);
scriptEngineSettingsDescription.putMapPropertyType("plugins", String.class, Object.class);
constructor.addTypeDescription(scriptEngineSettingsDescription);
constructor.addTypeDescription(sslSettings);
constructor.addTypeDescription(authenticationSettings);
constructor.addTypeDescription(serverMetricsDescription);
constructor.addTypeDescription(consoleReporterDescription);
constructor.addTypeDescription(csvReporterDescription);
constructor.addTypeDescription(jmxReporterDescription);
constructor.addTypeDescription(slf4jReporterDescription);
constructor.addTypeDescription(gangliaReporterDescription);
constructor.addTypeDescription(graphiteReporterDescription);
代码示例来源:origin: openbaton/NFVO
public static VNFDTemplate fileToVNFDTemplate(String fileName) throws FileNotFoundException {
InputStream tosca = new FileInputStream(new File(fileName));
Constructor constructor = new Constructor(VNFDTemplate.class);
TypeDescription projectDesc = new TypeDescription(VNFDTemplate.class);
constructor.addTypeDescription(projectDesc);
Yaml yaml = new Yaml(constructor);
return yaml.loadAs(tosca, VNFDTemplate.class);
}
代码示例来源:origin: openbaton/NFVO
public static VNFDTemplate bytesToVNFDTemplate(ByteArrayOutputStream b) {
Constructor constructor = new VnfdTemplateConstructor();
TypeDescription projectDesc = new TypeDescription(VNFDTemplate.class);
constructor.addTypeDescription(projectDesc);
Yaml yaml = new Yaml(constructor);
return yaml.loadAs(new ByteArrayInputStream(b.toByteArray()), VNFDTemplate.class);
}
代码示例来源:origin: paypal/SeLion
private Yaml constructYaml(Class<?> cls) {
if (cls != null) {
Constructor constructor = new Constructor();
constructor.addTypeDescription(new TypeDescription(cls, "!" + cls.getSimpleName()));
return new Yaml(constructor);
}
return new Yaml();
}
代码示例来源:origin: com.meltmedia.cadmium/cadmium-core
/**
* Overridden to capture what tags are defined specially.
*/
@Override
public TypeDescription addTypeDescription(TypeDescription definition) {
if(definition != null && definition.getTag() != null) {
tagsDefined.add(definition.getTag());
}
return super.addTypeDescription(definition);
}
代码示例来源:origin: io.engineblock/at-csv
private Yaml getCustomYaml() {
Constructor constructor = new Constructor(CSVStmtDoc.class);
TypeDescription tds = new TypeDescription(CSVStmtDoc.class);
tds.putListPropertyType("blocks", CSVStmtBlock.class);
constructor.addTypeDescription(tds);
return new Yaml(constructor);
}
代码示例来源:origin: org.apache.storm/flux-core
private static Yaml yaml() {
TypeDescription topologyDescription = new TypeDescription(TopologyDef.class);
topologyDescription.putListPropertyType("spouts", SpoutDef.class);
topologyDescription.putListPropertyType("bolts", BoltDef.class);
topologyDescription.putListPropertyType("includes", IncludeDef.class);
Constructor constructor = new Constructor(TopologyDef.class);
constructor.addTypeDescription(topologyDescription);
Yaml yaml = new Yaml(constructor);
return yaml;
}
代码示例来源:origin: openbaton/NFVO
@Test
@Ignore
public void testVNFDTemplate() throws FileNotFoundException {
InputStream vnfdFile =
new FileInputStream(new File("src/main/resources/Testing/testVNFDTemplate.yaml"));
Constructor constructor = new Constructor(VNFDTemplate.class);
TypeDescription typeDescription = new TypeDescription(VNFDTemplate.class);
constructor.addTypeDescription(typeDescription);
Yaml yaml = new Yaml(constructor);
VNFDTemplate vnfdInput = yaml.loadAs(vnfdFile, VNFDTemplate.class);
System.out.println(vnfdInput.toString());
}
代码示例来源: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;
}
}
内容来源于网络,如有侵权,请联系作者删除!