Search in sources :

Example 16 with Representer

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);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) PropertyUtils(org.yaml.snakeyaml.introspector.PropertyUtils) Constructor(org.yaml.snakeyaml.constructor.Constructor) TypeDescription(org.yaml.snakeyaml.TypeDescription) DumperOptions(org.yaml.snakeyaml.DumperOptions) Yaml(org.yaml.snakeyaml.Yaml)

Example 17 with Representer

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);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) DumperOptions(org.yaml.snakeyaml.DumperOptions) Tag(org.yaml.snakeyaml.nodes.Tag) RegularFileProperty(org.gradle.api.file.RegularFileProperty) Property(org.gradle.api.provider.Property) Yaml(org.yaml.snakeyaml.Yaml)

Example 18 with Representer

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");
}
Also used : YamlMapper(team.unnamed.mappa.yaml.mapper.YamlMapper) Command(me.fixeddev.commandflow.command.Command) MapSchemeFactory(team.unnamed.mappa.model.map.scheme.MapSchemeFactory) Commands(team.unnamed.mappa.internal.command.Commands) SimpleCommandManager(me.fixeddev.commandflow.SimpleCommandManager) DumperOptions(org.yaml.snakeyaml.DumperOptions) MessageHandler(me.yushust.message.MessageHandler) TranslationNode(team.unnamed.mappa.object.TranslationNode) BasicMappaModule(team.unnamed.mappa.internal.injector.BasicMappaModule) Map(java.util.Map) MapScheme(team.unnamed.mappa.model.map.scheme.MapScheme) MappaBootstrap(team.unnamed.mappa.MappaBootstrap) MappaConstructor(team.unnamed.mappa.yaml.constructor.MappaConstructor) MappaPartModule(team.unnamed.mappa.internal.command.MappaPartModule) SubCommandPart(me.fixeddev.commandflow.part.defaults.SubCommandPart) ToolHandler(team.unnamed.mappa.internal.region.ToolHandler) Properties(java.util.Properties) CommandPart(me.fixeddev.commandflow.part.CommandPart) ParseException(team.unnamed.mappa.throwable.ParseException) Collection(java.util.Collection) PropertiesFileSource(me.yushust.message.source.properties.PropertiesFileSource) MapSession(team.unnamed.mappa.model.map.MapSession) PartInjector(me.fixeddev.commandflow.annotated.part.PartInjector) RegionRegistry(team.unnamed.mappa.internal.region.RegionRegistry) Nullable(org.jetbrains.annotations.Nullable) MappaAPI(team.unnamed.mappa.MappaAPI) java.io(java.io) MappaTextHandler(team.unnamed.mappa.internal.message.MappaTextHandler) Representer(org.yaml.snakeyaml.representer.Representer) YamlMapper(team.unnamed.mappa.yaml.mapper.YamlMapper) ParseRuntimeException(team.unnamed.mappa.throwable.ParseRuntimeException) MappaInjector(team.unnamed.mappa.internal.injector.MappaInjector) DefaultsModule(me.fixeddev.commandflow.annotated.part.defaults.DefaultsModule) PartInjector(me.fixeddev.commandflow.annotated.part.PartInjector) TranslationNode(team.unnamed.mappa.object.TranslationNode) MessageHandler(me.yushust.message.MessageHandler) Properties(java.util.Properties) MappaBootstrap(team.unnamed.mappa.MappaBootstrap) MappaInjector(team.unnamed.mappa.internal.injector.MappaInjector) DumperOptions(org.yaml.snakeyaml.DumperOptions) SimpleCommandManager(me.fixeddev.commandflow.SimpleCommandManager) DefaultsModule(me.fixeddev.commandflow.annotated.part.defaults.DefaultsModule) MappaTextHandler(team.unnamed.mappa.internal.message.MappaTextHandler) BasicMappaModule(team.unnamed.mappa.internal.injector.BasicMappaModule) MapScheme(team.unnamed.mappa.model.map.scheme.MapScheme) MappaConstructor(team.unnamed.mappa.yaml.constructor.MappaConstructor) MappaPartModule(team.unnamed.mappa.internal.command.MappaPartModule) MapSession(team.unnamed.mappa.model.map.MapSession) PropertiesFileSource(me.yushust.message.source.properties.PropertiesFileSource) MapSchemeFactory(team.unnamed.mappa.model.map.scheme.MapSchemeFactory) Representer(org.yaml.snakeyaml.representer.Representer) ParseRuntimeException(team.unnamed.mappa.throwable.ParseRuntimeException) ParseException(team.unnamed.mappa.throwable.ParseException) Map(java.util.Map)

Example 19 with Representer

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();
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) LoaderOptions(org.yaml.snakeyaml.LoaderOptions) Tag(org.yaml.snakeyaml.nodes.Tag) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream)

Example 20 with Representer

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);
}
Also used : Representer(org.yaml.snakeyaml.representer.Representer) Constructor(org.yaml.snakeyaml.constructor.Constructor) Config(io.kamax.mxgwd.config.Config) Yaml(org.yaml.snakeyaml.Yaml) FileInputStream(java.io.FileInputStream)

Aggregations

Representer (org.yaml.snakeyaml.representer.Representer)82 Yaml (org.yaml.snakeyaml.Yaml)77 DumperOptions (org.yaml.snakeyaml.DumperOptions)54 Constructor (org.yaml.snakeyaml.constructor.Constructor)25 LoaderOptions (org.yaml.snakeyaml.LoaderOptions)21 FileInputStream (java.io.FileInputStream)12 SafeConstructor (org.yaml.snakeyaml.constructor.SafeConstructor)11 IOException (java.io.IOException)7 Tag (org.yaml.snakeyaml.nodes.Tag)7 File (java.io.File)6 TypeDescription (org.yaml.snakeyaml.TypeDescription)6 BaseConstructor (org.yaml.snakeyaml.constructor.BaseConstructor)5 FileNotFoundException (java.io.FileNotFoundException)4 InputStream (java.io.InputStream)4 PropertyUtils (org.yaml.snakeyaml.introspector.PropertyUtils)4 FileOutputStream (java.io.FileOutputStream)3 FileReader (java.io.FileReader)3 OutputStreamWriter (java.io.OutputStreamWriter)3 PrintWriter (java.io.PrintWriter)3 Map (java.util.Map)3