当前位置: 首页>>代码示例>>Java>>正文


Java Representer.addClassTag方法代码示例

本文整理汇总了Java中org.yaml.snakeyaml.representer.Representer.addClassTag方法的典型用法代码示例。如果您正苦于以下问题:Java Representer.addClassTag方法的具体用法?Java Representer.addClassTag怎么用?Java Representer.addClassTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.yaml.snakeyaml.representer.Representer的用法示例。


在下文中一共展示了Representer.addClassTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newYaml

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的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);
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:25,代码来源:YamlFactory.java

示例2: testLocalTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
/**
 * use wrapper with local tag
 */
public void testLocalTag() {
    JavaBeanWithStaticState bean = new JavaBeanWithStaticState();
    bean.setName("Bahrack");
    bean.setAge(-47);
    JavaBeanWithStaticState.setType("Type3");
    JavaBeanWithStaticState.color = "Violet";
    Representer repr = new Representer();
    repr.addClassTag(Wrapper.class, new Tag("!mybean"));
    Yaml yaml = new Yaml(repr);
    String output = yaml.dump(new Wrapper(bean));
    // System.out.println(output);
    assertEquals("!mybean {age: -47, color: Violet, name: Bahrack, type: Type3}\n", output);
    // parse back to instance
    Constructor constr = new Constructor();
    TypeDescription description = new TypeDescription(Wrapper.class, new Tag("!mybean"));
    constr.addTypeDescription(description);
    yaml = new Yaml(constr);
    Wrapper wrapper = (Wrapper) yaml.load(output);
    JavaBeanWithStaticState bean2 = wrapper.createBean();
    assertEquals(-47, bean2.getAge());
    assertEquals("Bahrack", bean2.getName());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:26,代码来源:StaticFieldsWrapperTest.java

示例3: testEmitWithTags

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testEmitWithTags() {
    TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
    DumperOptions options = new DumperOptions();
    options.setExplicitStart(true);
    Representer repr = new Representer();
    repr.addClassTag(TestObject.class, new Tag("!ruby/object:Test::Module::Object"));
    repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
    repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
    Yaml yaml2 = new Yaml(repr, options);
    String output = yaml2.dump(result);
    // System.out.println(output);
    assertTrue("Tags must be present.",
            output.startsWith("--- !ruby/object:Test::Module::Object"));
    assertTrue("Tags must be present: " + output,
            output.contains("!ruby/object:Test::Module::Sub1"));
    assertTrue("Tags must be present.", output.contains("!ruby/object:Test::Module::Sub2"));
    // parse back.
    TestObject result2 = parseObject(output);
    assertEquals(0, result2.getSub1().getAtt2());
    assertEquals("MyString", result2.getSub2().getAtt1());
    assertEquals(1, result2.getSub2().getAtt2().size());
    assertEquals(12345, result2.getSub2().getAtt3());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:24,代码来源:RubyTest.java

示例4: testEmitWithTags2WithoutTagForParentJavabean

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testEmitWithTags2WithoutTagForParentJavabean() {
    TestObject result = parseObject(Util.getLocalResource("ruby/ruby1.yaml"));
    DumperOptions options = new DumperOptions();
    options.setExplicitStart(true);
    Representer repr = new Representer();
    repr.addClassTag(Sub1.class, new Tag("!ruby/object:Test::Module::Sub1"));
    repr.addClassTag(Sub2.class, new Tag("!ruby/object:Test::Module::Sub2"));
    Yaml yaml2 = new Yaml(repr, options);
    String output = yaml2.dump(result);
    // System.out.println(output);
    assertTrue("Tags must be present.",
            output.startsWith("--- !!org.yaml.snakeyaml.ruby.TestObject"));
    assertTrue("Tags must be present: " + output,
            output.contains("!ruby/object:Test::Module::Sub1"));
    assertTrue("Tags must be present.", output.contains("!ruby/object:Test::Module::Sub2"));
    // parse back.
    TestObject result2 = parseObject(output);
    assertEquals(0, result2.getSub1().getAtt2());
    assertEquals("MyString", result2.getSub2().getAtt1());
    assertEquals(1, result2.getSub2().getAtt2().size());
    assertEquals(12345, result2.getSub2().getAtt3());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:23,代码来源:RubyTest.java

示例5: testDumpClassTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testDumpClassTag() {
    Car car = new Car();
    car.setPlate("12-XP-F4");
    List<Wheel> wheels = new ArrayList<Wheel>();
    for (int i = 1; i < 6; i++) {
        Wheel wheel = new Wheel();
        wheel.setId(i);
        wheels.add(wheel);
    }
    car.setWheels(wheels);
    Representer representer = new Representer();
    representer.addClassTag(Car.class, new Tag("!car"));
    representer.addClassTag(Wheel.class, Tag.MAP);
    Yaml yaml = new Yaml(representer);
    String output = yaml.dump(car);
    assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), output);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:18,代码来源:ClassTagsTest.java

示例6: testLoadClassTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testLoadClassTag() {
    Constructor constructor = new Constructor();
    constructor.addTypeDescription(new TypeDescription(Car.class, "!car"));
    Yaml yaml = new Yaml(constructor);
    Car car = (Car) yaml.load(Util.getLocalResource("constructor/car-without-tags.yaml"));
    assertEquals("12-XP-F4", car.getPlate());
    List<Wheel> wheels = car.getWheels();
    assertNotNull(wheels);
    assertEquals(5, wheels.size());
    Wheel w1 = wheels.get(0);
    assertEquals(1, w1.getId());
    //
    String carYaml1 = new Yaml().dump(car);
    assertTrue(carYaml1.startsWith("!!org.yaml.snakeyaml.constructor.Car"));
    //
    Representer representer = new Representer();
    representer.addClassTag(Car.class, new Tag("!car"));
    yaml = new Yaml(representer);
    String carYaml2 = yaml.dump(car);
    assertEquals(Util.getLocalResource("constructor/car-without-tags.yaml"), carYaml2);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:22,代码来源:ImplicitTagsTest.java

示例7: configYamlFormat

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
private static void configYamlFormat(final ToolBelt belt, final AppConfig config) {
    DumperOptions dumperOptions = new DumperOptions();
    dumperOptions.setDefaultFlowStyle(
            "BLOCK".equalsIgnoreCase(config.getString("RD_YAML_FLOW", "BLOCK")) ?
            DumperOptions.FlowStyle.BLOCK :
            DumperOptions.FlowStyle.FLOW
    );
    dumperOptions.setPrettyFlow(config.getBool("RD_YAML_PRETTY", true));
    Representer representer = new Representer();
    representer.addClassTag(JobItem.class, Tag.MAP);
    representer.addClassTag(ScheduledJobItem.class, Tag.MAP);
    representer.addClassTag(DateInfo.class, Tag.MAP);
    representer.addClassTag(Execution.class, Tag.MAP);
    belt.formatter(new YamlFormatter(representer, dumperOptions));
    belt.channels().infoEnabled(false);
    belt.channels().warningEnabled(false);
    belt.channels().errorEnabled(false);
}
 
开发者ID:rundeck,项目名称:rundeck-cli,代码行数:19,代码来源:Main.java

示例8: dumpConfiguration

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
private void dumpConfiguration(Path configFilePath) {
    try (FileWriter fileWriter = new FileWriter(configFilePath.toFile())) {
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

        Representer representer = new Representer() {
            @Override
            protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,Tag customTag) {
                // if value of property is null, ignore it.
                if (propertyValue == null) {
                    return null;
                }
                else {
                    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
                }
            }
        };

        representer.addClassTag(Configuration.class, Tag.MAP);

        Yaml yaml = new Yaml(representer, options);
        yaml.dump(configuration, fileWriter);
    } catch (IOException e) {
        throw new RuntimeException("Failed to dump configuration in file " + configFilePath, e);
    }
}
 
开发者ID:arquillian,项目名称:smart-testing,代码行数:27,代码来源:ProjectConfigurator.java

示例9: getYaml

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
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;
}
 
开发者ID:airbnb,项目名称:okreplay,代码行数:13,代码来源:YamlTapeLoader.java

示例10: testABWithCustomTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testABWithCustomTag() {
    SuperSaverAccount supersaver = new SuperSaverAccount();
    GeneralAccount generalAccount = new GeneralAccount();

    CustomerAB customerAB = new CustomerAB();
    ArrayList<Account> all = new ArrayList<Account>();
    all.add(supersaver);
    all.add(generalAccount);
    ArrayList<GeneralAccount> general = new ArrayList<GeneralAccount>();
    general.add(generalAccount);
    general.add(supersaver);

    customerAB.aAll = all;
    customerAB.bGeneral = general;

    Constructor constructor = new Constructor();
    Representer representer = new Representer();
    Tag generalAccountTag = new Tag("!GA");
    constructor
            .addTypeDescription(new TypeDescription(GeneralAccount.class, generalAccountTag));
    representer.addClassTag(GeneralAccount.class, generalAccountTag);

    Yaml yaml = new Yaml(constructor, representer);
    String dump = yaml.dump(customerAB);
    // System.out.println(dump);
    CustomerAB parsed = (CustomerAB) yaml.load(dump);
    assertNotNull(parsed);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:29,代码来源:PropOrderInfluenceWhenAliasedInGenericCollectionTest.java

示例11: testABPropertyWithCustomTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testABPropertyWithCustomTag() {
    SuperSaverAccount supersaver = new SuperSaverAccount();
    GeneralAccount generalAccount = new GeneralAccount();

    CustomerAB_Property customerAB_property = new CustomerAB_Property();
    ArrayList<Account> all = new ArrayList<Account>();
    all.add(supersaver);
    all.add(generalAccount);
    ArrayList<GeneralAccount> general = new ArrayList<GeneralAccount>();
    general.add(generalAccount);
    general.add(supersaver);

    customerAB_property.acc = generalAccount;
    customerAB_property.bGeneral = general;

    Constructor constructor = new Constructor();
    Representer representer = new Representer();

    Tag generalAccountTag = new Tag("!GA");
    constructor
            .addTypeDescription(new TypeDescription(GeneralAccount.class, generalAccountTag));
    representer.addClassTag(GeneralAccount.class, generalAccountTag);

    Yaml yaml = new Yaml(constructor, representer);
    String dump = yaml.dump(customerAB_property);
    // System.out.println(dump);
    CustomerAB_Property parsed = (CustomerAB_Property) yaml.load(dump);
    assertNotNull(parsed);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:30,代码来源:PropOrderInfluenceWhenAliasedInGenericCollectionTest.java

示例12: testDumpCustomTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testDumpCustomTag() {
    Académico obj = new Académico();
    obj.setId(123);
    obj.setName("Foo bar 123");
    Representer repr = new Representer();
    repr.addClassTag(Académico.class, new Tag("!foo"));
    Yaml yaml = new Yaml(repr);
    String result = yaml.dump(obj);
    assertEquals("!foo {id: 123, name: Foo bar 123}\n", result);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:11,代码来源:NonAsciiCharsInClassNameTest.java

示例13: testDumpEscapedTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testDumpEscapedTag() {
    Académico obj = new Académico();
    obj.setId(123);
    obj.setName("Foo bar 123");
    Representer repr = new Representer();
    repr.addClassTag(Académico.class, new Tag("!Académico"));
    Yaml yaml = new Yaml(repr);
    String result = yaml.dump(obj);
    assertEquals("!Acad%C3%A9mico {id: 123, name: Foo bar 123}\n", result);
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:11,代码来源:NonAsciiCharsInClassNameTest.java

示例14: testLongRepresenter

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testLongRepresenter() {
    DumperOptions options = new DumperOptions();
    options.setDefaultScalarStyle(DumperOptions.ScalarStyle.DOUBLE_QUOTED);
    Representer repr = new Representer();
    repr.addClassTag(Long.class, new Tag("!!java.lang.Long"));
    Yaml yaml = new Yaml(repr, options);

    Foo foo = new Foo();
    String output = yaml.dump(foo);
    // System.out.println(output);
    Foo foo2 = (Foo) yaml.load(output);
    assertEquals(new Long(42L), foo2.getBar());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:14,代码来源:LongTest.java

示例15: testWithGlobalTag

import org.yaml.snakeyaml.representer.Representer; //导入方法依赖的package包/类
public void testWithGlobalTag() {
    Map<MyWheel, Date> wheels = new TreeMap<MyWheel, Date>();
    long time = 1248212168084L;
    for (int i = 1; i < 6; i++) {
        MyWheel mw = new MyWheel();
        mw.setId(i);
        mw.setBrand(mw.getBrand() + String.valueOf(i));
        wheels.put(mw, new Date(time + i));
    }
    MyCar c = new MyCar();
    c.setPlate("00-FF-Q2");
    c.setWheels(wheels);
    Representer representer = new Representer();
    representer.addClassTag(MyWheel.class, Tag.MAP);
    Yaml yaml = new Yaml(representer);
    String output = yaml.dump(c);
    assertEquals(Util.getLocalResource("javabeans/mycar-with-global-tag1.yaml"), output);
    // load
    Yaml beanLoader = new Yaml();
    MyCar car = beanLoader.loadAs(output, MyCar.class);
    assertNotNull(car);
    assertEquals("00-FF-Q2", car.getPlate());
    assertEquals(5, car.getWheels().size());
    for (Date d : car.getWheels().values()) {
        // give a day for any timezone
        assertTrue(d.before(new Date(time + 1000 * 60 * 60 * 24)));
        assertTrue(d.after(new Date(time)));
    }
    Object wheel = car.getWheels().keySet().iterator().next();
    assertTrue(wheel instanceof MyWheel);
    MyWheel w = (MyWheel) wheel;
    assertEquals(1, w.getId());
    assertEquals("Pirelli1", w.getBrand());
}
 
开发者ID:bmoliveira,项目名称:snake-yaml,代码行数:35,代码来源:TypeSafeCollectionsTest.java


注:本文中的org.yaml.snakeyaml.representer.Representer.addClassTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。