當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。