use of org.yaml.snakeyaml.representer.Representer in project waggle-dance by ExpediaGroup.
the class YamlFactory method newYaml.
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);
}
use of org.yaml.snakeyaml.representer.Representer in project spring-security by spring-projects.
the class UpdateAntoraVersionTask method getYaml.
private Yaml getYaml() {
Representer representer = new Representer() {
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, org.yaml.snakeyaml.introspector.Property property, Object propertyValue, Tag customTag) {
// Don't write out null values
if (propertyValue == null) {
return null;
} else {
return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
}
};
representer.addClassTag(AntoraYml.class, Tag.MAP);
DumperOptions ymlOptions = new DumperOptions();
ymlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
ymlOptions.setDefaultScalarStyle(DumperOptions.ScalarStyle.SINGLE_QUOTED);
return new Yaml(representer, ymlOptions);
}
use of org.yaml.snakeyaml.representer.Representer in project mappa by unnamed.
the class YamlTest method main.
public static void main(String[] args) throws ParseException, IOException {
DumperOptions options = new DumperOptions();
File file = new File("schemes.yml");
Representer representer = new Representer();
YamlMapper yamlMapper = new YamlMapper(new MappaConstructor(), representer, options);
Map<String, Object> load = yamlMapper.load(file);
System.out.println("Load:");
map(load);
MappaInjector injector = MappaInjector.newInjector(new BasicMappaModule());
MapSchemeFactory factory = MapScheme.factory(injector);
MapScheme scheme = factory.from("mabedwars", (Map<String, Object>) load.get("MABedwars"));
System.out.println("Scheme:");
map(scheme.getProperties());
System.out.println();
Map<String, Object> sessions = yamlMapper.loadSessions(scheme, new File("serialized.yml"));
System.out.println("Sessions:");
map(sessions);
System.out.println();
File folder = new File(System.getProperty("user.home"));
// Creating and refill translations
File langUs = new File(folder, "lang_en_US.properties");
Properties properties = new Properties();
properties.load(new FileInputStream(langUs));
for (TranslationNode value : TranslationNode.values()) {
Object node = properties.get(value.getNode());
if (node == null) {
properties.put(value.getNode(), value.getDefaultMessage());
}
}
properties.store(new FileOutputStream(langUs), null);
MessageHandler handler = MessageHandler.of(new PropertiesFileSource(folder, "lang_%lang%.properties"), handle -> handle.specify(PrintStream.class).setMessageSender((out, mode, message) -> out.println(message)).setLinguist(out -> "en_US"));
MappaTextHandler textHandler = new MappaTextHandler(handler, context -> System.out, null);
System.out.println("Session resume:");
try {
Map<String, Object> myTest = (Map<String, Object>) sessions.get("MyTest");
System.out.println("My test:");
map(myTest);
MapSession resumeSession = scheme.resumeSession("MyTest", myTest);
map(resumeSession.getProperties());
File result = new File("result.yml");
result.createNewFile();
yamlMapper.saveTo(result, resumeSession);
} catch (ParseException e) {
textHandler.send(System.out, e.getTextNode());
throw e;
} catch (ParseRuntimeException e) {
textHandler.send(System.out, e.getTextNode());
throw e;
}
System.out.println();
System.out.println("Bootstrap:");
SimpleCommandManager commandManager = new SimpleCommandManager();
YamlTest api = new YamlTest();
PartInjector partInjector = Commands.newInjector(new DefaultsModule(), new MappaPartModule(api));
MappaBootstrap bootstrap = new MappaBootstrap(yamlMapper, factory, new File(""), commandManager, partInjector, textHandler);
api.bootstrap = bootstrap;
bootstrap.loadSchemes(file, System.out);
mapCommand(bootstrap.getCommandManager().getCommand("mabedwars").orElseThrow(NullPointerException::new), null, "-> ");
System.out.println("end");
}
use of org.yaml.snakeyaml.representer.Representer in project Eidolons by IDemiurge.
the class UnitGenerator method main.
public static void main(String[] s) throws FileNotFoundException {
Representer representer = new Representer();
representer.addClassTag(YamlEntity.class, new Tag("!yah"));
// Yaml yaml = new Yaml(new Constructor(UnitClass.class), new Representer(), new DumperOptions(),
// new LoaderOptions(){
// @Override
// public boolean isEnumCaseSensitive() {
// return false;
// }
// }, new Resolver());
Yaml yaml = new Yaml(new LoaderOptions() {
@Override
public boolean isEnumCaseSensitive() {
return false;
}
});
Object load = yaml.loadAs(new FileInputStream("C:\\code\\Eidolons\\" + "DungeonCraft\\src\\main\\resources\\data\\unitclass.yaml"), UnitClass.class);
// yaml.represent(load);
load.getClass();
}
use of org.yaml.snakeyaml.representer.Representer in project mxgwd by kamax-io.
the class YamlConfigLoader method loadFromFile.
public static Config loadFromFile(String path) throws IOException {
Representer rep = new Representer();
rep.getPropertyUtils().setAllowReadOnlyProperties(true);
rep.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(new Constructor(Config.class), rep);
Object o = yaml.load(new FileInputStream(path));
return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), Config.class);
}
Aggregations