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(); } } }
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(); } } }
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); }
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()); }
private static Yaml getYaml() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); StringExRepresent representer = new StringExRepresent(); PropertyUtils propertyUtils = representer.getPropertyUtils(); propertyUtils.setSkipMissingProperties(true); return new Yaml(new StringExConstructor(), representer, options); }
/** * @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; }
public static Yaml newYaml() { Representer representer = new Representer(); PropertyUtils propertyUtils = representer.getPropertyUtils(); propertyUtils.setSkipMissingProperties(true); propertyUtils.setBeanAccess(BeanAccess.FIELD); propertyUtils.setAllowReadOnlyProperties(true); return new Yaml(representer); }
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()); }
public void testYamlRepresenterWithPropertyUtils() { Representer representer2 = new Representer(); PropertyUtils pu = new PropertyUtils(); representer2.setPropertyUtils(pu); Yaml yaml = new Yaml(representer2); assertSame(pu, yaml.constructor.getPropertyUtils()); assertSame(pu, yaml.representer.getPropertyUtils()); }
@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()); }
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() ); }
protected Yaml initialValue() { DumperOptions options = new DumperOptions(); options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); CustomClassLoaderConstructor constructor = new CustomClassLoaderConstructor(getClass().getClassLoader()); PropertyUtils propertyUtils = constructor.getPropertyUtils(); propertyUtils.setSkipMissingProperties(true); constructor.setPropertyUtils(propertyUtils); return new Yaml(constructor, new Representer(), options); }
public void setPropertyUtils(PropertyUtils propertyUtils) { this.propertyUtils = propertyUtils; this.explicitPropertyUtils = true; }
public void setPropertyUtils(PropertyUtils propertyUtils) { this.propertyUtils = propertyUtils; explicitPropertyUtils = true; }
public void setPropertyUtils(final PropertyUtils propertyUtils) { this.propertyUtils = propertyUtils; this.explicitPropertyUtils = true; }
public void setPropertyUtils(final PropertyUtils propertyUtils) { this.propertyUtils = propertyUtils; explicitPropertyUtils = true; }