本文整理汇总了Java中org.yaml.snakeyaml.constructor.Constructor.setPropertyUtils方法的典型用法代码示例。如果您正苦于以下问题:Java Constructor.setPropertyUtils方法的具体用法?Java Constructor.setPropertyUtils怎么用?Java Constructor.setPropertyUtils使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.constructor.Constructor
的用法示例。
在下文中一共展示了Constructor.setPropertyUtils方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadYaml
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
private Object loadYaml(File omapfile) throws IOException {
FileReader reader = new FileReader(omapfile);
try {
Constructor constructor = new Constructor();
PropertyUtils putils = new PropertyUtils();
putils.setSkipMissingProperties(true);
constructor.setPropertyUtils(putils);
Yaml yaml = new Yaml(constructor);
return yaml.load(reader);
} catch (Throwable t) {
throw new RuntimeException("Error loading yaml from: " + omapfile.getAbsolutePath() + "\n" + t.getMessage(), t);
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例2: loadYaml
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
private Object loadYaml(File file) throws FileNotFoundException {
FileReader reader = new FileReader(file);
try {
Constructor constructor = new Constructor();
PropertyUtils putils = new PropertyUtils();
putils.setSkipMissingProperties(true);
constructor.setPropertyUtils(putils);
Yaml yaml = new Yaml(constructor);
return yaml.load(reader);
} catch (Throwable t) {
throw new RuntimeException("Error loading yaml from: " + file.getAbsolutePath() + "\n" + t.getMessage(), t);
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例3: newYaml
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
public static Yaml newYaml() {
PropertyUtils propertyUtils = new AdvancedPropertyUtils();
propertyUtils.setSkipMissingProperties(true);
Constructor constructor = new Constructor(Federations.class);
TypeDescription federationDescription = new TypeDescription(Federations.class);
federationDescription.putListPropertyType("federatedMetaStores", FederatedMetaStore.class);
constructor.addTypeDescription(federationDescription);
constructor.setPropertyUtils(propertyUtils);
Representer representer = new AdvancedRepresenter();
representer.setPropertyUtils(new FieldOrderPropertyUtils());
representer.addClassTag(Federations.class, Tag.MAP);
representer.addClassTag(AbstractMetaStore.class, Tag.MAP);
representer.addClassTag(WaggleDanceConfiguration.class, Tag.MAP);
representer.addClassTag(YamlStorageConfiguration.class, Tag.MAP);
representer.addClassTag(GraphiteConfiguration.class, Tag.MAP);
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setIndent(2);
dumperOptions.setDefaultFlowStyle(FlowStyle.BLOCK);
return new Yaml(constructor, representer, dumperOptions);
}
示例4: testErrorMessage
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
public void testErrorMessage() throws Exception {
BeanA1 b = new BeanA1();
b.setId(2l);
b.setName("name1");
Constructor c = new Constructor();
Representer r = new Representer();
PropertyUtils pu = new PropertyUtils();
c.setPropertyUtils(pu);
r.setPropertyUtils(pu);
pu.getProperties(BeanA1.class, BeanAccess.FIELD);
Yaml yaml = new Yaml(c, r);
// yaml.setBeanAccess(BeanAccess.FIELD);
String dump = yaml.dump(b);
BeanA1 b2 = (BeanA1) yaml.load(dump);
assertEquals(b.getId(), b2.getId());
assertEquals(b.getName(), b2.getName());
}
示例5: loadSettings
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
/**
* @author wasiq.bhamla
* @since 09-Jun-2017 5:00:19 PM
* @param cls
*/
@SuppressWarnings ("unchecked")
private <T> T loadSettings (final Class <T> cls) {
final String path = System.getProperty (this.key, this.value);
try (final InputStream in = getClass ().getResourceAsStream (path)) {
if (in != null) {
final Constructor ctor = new Constructor (cls);
final PropertyUtils propertyUtils = new PropertyUtils () {
@Override
public Property getProperty (final Class <? extends Object> obj, final String name) {
String propertyName = name;
if (propertyName.indexOf ('_') > -1) {
propertyName = CaseFormat.LOWER_UNDERSCORE.to (CaseFormat.LOWER_CAMEL, propertyName);
}
return super.getProperty (obj, propertyName);
}
};
ctor.setPropertyUtils (propertyUtils);
final Yaml yaml = new Yaml (ctor);
return (T) yaml.load (in);
}
}
catch (final Exception e) {
fail (CoteafsConfigNotLoadedError.class, "Error loading config file.", e);
}
final String MSG = "%s not found.";
fail (CoteafsConfigFileNotFoundError.class, String.format (MSG, path));
return null;
}
示例6: testYamlConstructorWithPropertyUtils
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
public void testYamlConstructorWithPropertyUtils() {
Constructor constructor1 = new Constructor();
PropertyUtils pu = new PropertyUtils();
constructor1.setPropertyUtils(pu);
Yaml yaml = new Yaml(constructor1);
assertSame(pu, yaml.constructor.getPropertyUtils());
assertSame(pu, yaml.representer.getPropertyUtils());
}
示例7: testYamlConstructorANDRepresenterWithPropertyUtils
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
@Test
public void testYamlConstructorANDRepresenterWithPropertyUtils() {
Constructor constructor = new Constructor();
PropertyUtils pu_c = new PropertyUtils();
constructor.setPropertyUtils(pu_c);
Representer representer = new Representer();
PropertyUtils pu_r = new PropertyUtils();
representer.setPropertyUtils(pu_r);
Yaml yaml = new Yaml(constructor, representer);
assertSame(pu_c, yaml.constructor.getPropertyUtils());
assertSame(pu_r, yaml.representer.getPropertyUtils());
}
示例8: PluginManager
import org.yaml.snakeyaml.constructor.Constructor; //导入方法依赖的package包/类
public PluginManager(ProxyServer proxy)
{
this.proxy = proxy;
// Ignore unknown entries in the plugin descriptions
Constructor yamlConstructor = new Constructor();
PropertyUtils propertyUtils = yamlConstructor.getPropertyUtils();
propertyUtils.setSkipMissingProperties( true );
yamlConstructor.setPropertyUtils( propertyUtils );
yaml = new Yaml( yamlConstructor );
eventBus = new EventBus( proxy.getLogger() );
}