當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeDescription.putMapPropertyType方法代碼示例

本文整理匯總了Java中org.yaml.snakeyaml.TypeDescription.putMapPropertyType方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeDescription.putMapPropertyType方法的具體用法?Java TypeDescription.putMapPropertyType怎麽用?Java TypeDescription.putMapPropertyType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.yaml.snakeyaml.TypeDescription的用法示例。


在下文中一共展示了TypeDescription.putMapPropertyType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testArrayAsMapValueWithTypeDespriptor

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public void testArrayAsMapValueWithTypeDespriptor() {
    Yaml yaml2dump = new Yaml();
    yaml2dump.setBeanAccess(BeanAccess.FIELD);
    A data = createA();
    String dump = yaml2dump.dump(data);
    // System.out.println(dump);

    TypeDescription aTypeDescr = new TypeDescription(A.class);
    aTypeDescr.putMapPropertyType("meta", String.class, String[].class);

    Constructor c = new Constructor();
    c.addTypeDescription(aTypeDescr);
    Yaml yaml2load = new Yaml(c);
    yaml2load.setBeanAccess(BeanAccess.FIELD);

    A loaded = (A) yaml2load.load(dump);

    assertEquals(data.meta.size(), loaded.meta.size());
    Set<Entry<String, String[]>> loadedMeta = loaded.meta.entrySet();
    for (Entry<String, String[]> entry : loadedMeta) {
        assertTrue(data.meta.containsKey(entry.getKey()));
        Assert.assertArrayEquals(data.meta.get(entry.getKey()), entry.getValue());
    }
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:25,代碼來源:ArrayInGenericCollectionTest.java

示例2: testTypeSafeMap

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public void testTypeSafeMap() {
    Constructor constructor = new Constructor(MyCar.class);
    TypeDescription carDescription = new TypeDescription(MyCar.class);
    carDescription.putMapPropertyType("wheels", MyWheel.class, Object.class);
    constructor.addTypeDescription(carDescription);
    Yaml yaml = new Yaml(constructor);
    MyCar car = (MyCar) yaml.load(Util
            .getLocalResource("constructor/car-no-root-class-map.yaml"));
    assertEquals("00-FF-Q2", car.getPlate());
    Map<MyWheel, Date> wheels = car.getWheels();
    assertNotNull(wheels);
    assertEquals(5, wheels.size());
    for (MyWheel wheel : wheels.keySet()) {
        assertTrue(wheel.getId() > 0);
        Date date = wheels.get(wheel);
        long time = date.getTime();
        assertTrue("It must be midnight.", time % 10000 == 0);
    }
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:20,代碼來源:TypeSafeCollectionsTest.java

示例3: ChronixSparkLoader

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public ChronixSparkLoader() {
    Representer representer = new Representer();
    representer.getPropertyUtils().setSkipMissingProperties(true);

    Constructor constructor = new Constructor(YamlConfiguration.class);

    TypeDescription typeDescription = new TypeDescription(ChronixYAMLConfiguration.class);
    typeDescription.putMapPropertyType("configurations", Object.class, ChronixYAMLConfiguration.IndividualConfiguration.class);
    constructor.addTypeDescription(typeDescription);

    Yaml yaml = new Yaml(constructor, representer);
    yaml.setBeanAccess(BeanAccess.FIELD);

    InputStream in = this.getClass().getClassLoader().getResourceAsStream("test_config.yml");
    chronixYAMLConfiguration = yaml.loadAs(in, ChronixYAMLConfiguration.class);
}
 
開發者ID:ChronixDB,項目名稱:chronix.spark,代碼行數:17,代碼來源:ChronixSparkLoader.java

示例4: testChildrenSetAsRoot

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testChildrenSetAsRoot() throws IOException, IntrospectionException {
    if (!GenericsBugDetector.isProperIntrospection()) {
        return;
    }
    String etalon = Util.getLocalResource("recursive/generics/with-children-as-set.yaml");

    Constructor constructor = new Constructor();
    TypeDescription humanDescription = new TypeDescription(HumanGen.class);
    humanDescription.putMapPropertyType("children", HumanGen.class, Object.class);
    constructor.addTypeDescription(humanDescription);

    Yaml yaml = new Yaml(constructor);
    Set<HumanGen> children2 = (Set<HumanGen>) yaml.load(etalon);
    assertNotNull(children2);
    assertEquals(2, children2.size());

    HumanGen firstChild = children2.iterator().next();

    HumanGen father2 = firstChild.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", firstChild.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), firstChild.getMother());
    assertSame(father2, firstChild.getMother().getPartner());

    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        assertSame(HumanGen.class, child.getClass()); // check if type
        // descriptor was correct
    }
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:34,代碼來源:HumanGenericsTest.java

示例5: testChildrenMapAsRoot

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testChildrenMapAsRoot() throws IOException, IntrospectionException {
    if (!GenericsBugDetector.isProperIntrospection()) {
        return;
    }
    String etalon = Util.getLocalResource("recursive/generics/with-children-as-map.yaml");

    Constructor constructor = new Constructor();
    TypeDescription Human2Description = new TypeDescription(HumanGen2.class);
    Human2Description.putMapPropertyType("children", HumanGen2.class, String.class);
    constructor.addTypeDescription(Human2Description);

    Yaml yaml = new Yaml(constructor);
    Map<HumanGen2, String> children2 = (Map<HumanGen2, String>) yaml.load(etalon);
    assertNotNull(children2);
    assertEquals(2, children2.size());

    Entry<HumanGen2, String> firstEntry = children2.entrySet().iterator().next();
    HumanGen2 firstChild = firstEntry.getKey();

    HumanGen2 father2 = firstChild.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", firstChild.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), firstChild.getMother());
    assertSame(father2, firstChild.getMother().getPartner());

    assertSame(father2.getPartner().getChildren(), children2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:30,代碼來源:HumanGenericsTest.java

示例6: testChildrenSetAsRoot

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testChildrenSetAsRoot() {
    String etalon = Util.getLocalResource("recursive/with-children-as-set.yaml");

    Constructor constructor = new Constructor();
    TypeDescription humanDescription = new TypeDescription(Human.class);
    humanDescription.putMapPropertyType("children", Human.class, Object.class);
    constructor.addTypeDescription(humanDescription);

    Yaml yaml = new Yaml(constructor);
    Set<Human> children2 = (Set<Human>) yaml.load(etalon);
    assertNotNull(children2);
    assertEquals(2, children2.size());

    Human firstChild = children2.iterator().next();

    Human father2 = firstChild.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", firstChild.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), firstChild.getMother());
    assertSame(father2, firstChild.getMother().getPartner());

    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        // check if type descriptor was correct
        assertSame(Human.class, child.getClass());
    }

    validateSet(children2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:33,代碼來源:HumanTest.java

示例7: testChildrenMapAsRoot

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testChildrenMapAsRoot() {
    String etalon = Util.getLocalResource("recursive/with-children-as-map.yaml");

    Constructor constructor = new Constructor();
    TypeDescription Human2Description = new TypeDescription(Human2.class);
    Human2Description.putMapPropertyType("children", Human2.class, String.class);
    constructor.addTypeDescription(Human2Description);

    Yaml yaml = new Yaml(constructor);
    Map<Human2, String> children2 = (Map<Human2, String>) yaml.load(etalon);
    assertNotNull(children2);
    assertEquals(2, children2.size());

    Entry<Human2, String> firstEntry = children2.entrySet().iterator().next();
    Human2 firstChild = firstEntry.getKey();

    Human2 father2 = firstChild.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", firstChild.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), firstChild.getMother());
    assertSame(father2, firstChild.getMother().getPartner());

    assertSame(father2.getPartner().getChildren(), children2);

    validateMapKeys(children2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:29,代碼來源:HumanTest.java

示例8: getYamlConstructor

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
private static Constructor getYamlConstructor() {
    Constructor constructor = new Constructor(TestConfiguration.class);

    TypeDescription testConfigurationTypeDescription = new TypeDescription(TestConfiguration.class);
    TypeDescription groupTypeDescription = new TypeDescription(Group.class);
    TypeDescription testCaseTypeDescription = new TypeDescription(TestCase.class);
    TypeDescription requestTypeDescription = new TypeDescription(RequestDefinition.class);
    TypeDescription responseTypeDescription = new TypeDescription(ResponseDefinition.class);
    TypeDescription retryStrategyTypeDescription = new TypeDescription(Retry.class);

    testConfigurationTypeDescription.putListPropertyType("groups", Group.class);
    groupTypeDescription.putListPropertyType("test", TestCase.class);
    testCaseTypeDescription.putListPropertyType("retry", Retry.class);
    testCaseTypeDescription.putListPropertyType("request", RequestDefinition.class);
    testCaseTypeDescription.putListPropertyType("response", ResponseDefinition.class);
    requestTypeDescription.putMapPropertyType("headers", String.class, String.class);
    responseTypeDescription.putMapPropertyType("headers", String.class, String.class);

    constructor.addTypeDescription(testConfigurationTypeDescription);
    constructor.addTypeDescription(groupTypeDescription);
    constructor.addTypeDescription(testCaseTypeDescription);
    constructor.addTypeDescription(retryStrategyTypeDescription);
    constructor.addTypeDescription(requestTypeDescription);
    constructor.addTypeDescription(responseTypeDescription);

    return constructor;
}
 
開發者ID:Neofonie,項目名稱:aiko,代碼行數:28,代碼來源:TestConfiguration.java

示例9: CustomConstructor

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
CustomConstructor(Class<?> theRoot)
{
    super(theRoot);

    TypeDescription seedDesc = new TypeDescription(ParameterizedClass.class);
    seedDesc.putMapPropertyType("parameters", String.class, String.class);
    addTypeDescription(seedDesc);
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:9,代碼來源:YamlConfigurationLoader.java

示例10: prepareMap

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
private void prepareMap(final Field field, final TypeDescription description, final Set<Class> classes, final Constructor constructor)
{
	final MapValueType mapType = field.getAnnotation(MapValueType.class);
	if (mapType != null)
	{
		final MapKeyType mapKeyType = field.getAnnotation(MapKeyType.class);
		description.putMapPropertyType(
				field.getName(), mapKeyType == null ? String.class : mapKeyType.value(), mapType.value());
		if (StorageObject.class.isAssignableFrom(mapType.value()) && !classes.contains(mapType.value()))
		{
			prepareConstructor(constructor, classes, mapType.value());
		}
	}
}
 
開發者ID:Curtis3321,項目名稱:Essentials,代碼行數:15,代碼來源:YamlStorageReader.java

示例11: testChildren

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public void testChildren() throws IOException, IntrospectionException {
    if (!GenericsBugDetector.isProperIntrospection()) {
        return;
    }
    HumanGen father = new HumanGen();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    HumanGen mother = new HumanGen();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    HumanGen son = new HumanGen();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    HumanGen daughter = new HumanGen();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    Set<HumanGen> children = new LinkedHashSet<HumanGen>(2);
    children.add(son);
    children.add(daughter);
    father.setChildren(children);
    mother.setChildren(children);
    //

    Constructor constructor = new Constructor();
    TypeDescription humanDescription = new TypeDescription(HumanGen.class);
    humanDescription.putMapPropertyType("children", HumanGen.class, Object.class);
    constructor.addTypeDescription(humanDescription);

    Yaml yaml = new Yaml(constructor);
    String output = yaml.dump(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/generics/with-children.yaml");
    assertEquals(etalon, output);
    //
    HumanGen son2 = (HumanGen) yaml.load(output);
    assertNotNull(son2);
    assertEquals("Son", son.getName());

    HumanGen father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    Set<HumanGen> children2 = father2.getChildren();
    assertEquals(2, children2.size());
    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        assertSame(HumanGen.class, child.getClass()); // check if type
        // descriptor was correct
    }
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:73,代碼來源:HumanGenericsTest.java

示例12: testChildren2

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public void testChildren2() throws IOException, IntrospectionException {
    if (!GenericsBugDetector.isProperIntrospection()) {
        return;
    }
    HumanGen2 father = new HumanGen2();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    HumanGen2 mother = new HumanGen2();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    HumanGen2 son = new HumanGen2();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    HumanGen2 daughter = new HumanGen2();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    HashMap<HumanGen2, String> children = new LinkedHashMap<HumanGen2, String>(2);
    children.put(son, "son");
    children.put(daughter, "daughter");
    father.setChildren(children);
    mother.setChildren(children);
    //
    Representer representer = new Representer();
    representer.addClassTag(HumanGen2.class, Tag.MAP);
    Yaml yaml = new Yaml(representer);
    String output = yaml.dump(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/generics/with-children-2.yaml");
    assertEquals(etalon, output);
    // load
    TypeDescription humanDescription = new TypeDescription(HumanGen2.class);
    humanDescription.putMapPropertyType("children", HumanGen2.class, String.class);
    Yaml beanLoader = new Yaml(new Constructor(humanDescription));
    //
    HumanGen2 son2 = beanLoader.loadAs(output, HumanGen2.class);
    assertNotNull(son2);
    assertEquals("Son", son.getName());

    HumanGen2 father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    Map<HumanGen2, String> children2 = father2.getChildren();
    assertEquals(2, children2.size());
    assertSame(father2.getPartner().getChildren(), children2);

}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:69,代碼來源:HumanGenericsTest.java

示例13: testChildren

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public void testChildren() {
    Human father = new Human();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    Human mother = new Human();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    Human son = new Human();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    Human daughter = new Human();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    Set<Human> children = new LinkedHashSet<Human>(2);
    children.add(son);
    children.add(daughter);
    father.setChildren(children);
    mother.setChildren(children);
    //
    Yaml beanDumper = new Yaml();
    String output = beanDumper.dumpAsMap(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/with-children.yaml");
    assertEquals(etalon, output);
    TypeDescription humanDescription = new TypeDescription(Human.class);
    humanDescription.putMapPropertyType("children", Human.class, Object.class);
    Yaml beanLoader = new Yaml(new Constructor(humanDescription));
    //
    Human son2 = beanLoader.loadAs(output, Human.class);
    assertNotNull(son2);
    assertEquals("Son", son.getName());

    Human father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    Set<Human> children2 = father2.getChildren();
    assertEquals(2, children2.size());
    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        // check if type descriptor was correct
        assertSame(Human.class, child.getClass());
    }

    // check if hashCode is correct
    validateSet(children2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:70,代碼來源:HumanTest.java

示例14: testChildrenPretty

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public void testChildrenPretty() {
    Human father = new Human();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    Human mother = new Human();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    Human son = new Human();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    Human daughter = new Human();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    Set<Human> children = new LinkedHashSet<Human>(2);
    children.add(son);
    children.add(daughter);
    father.setChildren(children);
    mother.setChildren(children);
    //
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(FlowStyle.FLOW);
    options.setPrettyFlow(true);
    Yaml beanDumper = new Yaml(options);
    String output = beanDumper.dump(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/with-children-pretty.yaml");
    assertEquals(etalon, output);
    TypeDescription humanDescription = new TypeDescription(Human.class);
    humanDescription.putMapPropertyType("children", Human.class, Object.class);
    Yaml beanLoader = new Yaml(new Constructor(humanDescription));
    //
    Human son2 = beanLoader.loadAs(output, Human.class);
    assertNotNull(son2);
    assertEquals("Son", son.getName());

    Human father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    Set<Human> children2 = father2.getChildren();
    assertEquals(2, children2.size());
    assertSame(father2.getPartner().getChildren(), children2);

    for (Object child : children2) {
        // check if type descriptor was correct
        assertSame(Human.class, child.getClass());
    }

    // check if hashCode is correct
    validateSet(children2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:73,代碼來源:HumanTest.java

示例15: testChildren2

import org.yaml.snakeyaml.TypeDescription; //導入方法依賴的package包/類
public void testChildren2() {
    Human2 father = new Human2();
    father.setName("Father");
    father.setBirthday(new Date(1000000000));
    father.setBirthPlace("Leningrad");
    father.setBankAccountOwner(father);
    //
    Human2 mother = new Human2();
    mother.setName("Mother");
    mother.setBirthday(new Date(100000000000L));
    mother.setBirthPlace("Saint-Petersburg");
    father.setPartner(mother);
    mother.setPartner(father);
    mother.setBankAccountOwner(father);
    //
    Human2 son = new Human2();
    son.setName("Son");
    son.setBirthday(new Date(310000000000L));
    son.setBirthPlace("Munich");
    son.setBankAccountOwner(father);
    son.setFather(father);
    son.setMother(mother);
    //
    Human2 daughter = new Human2();
    daughter.setName("Daughter");
    daughter.setBirthday(new Date(420000000000L));
    daughter.setBirthPlace("New York");
    daughter.setBankAccountOwner(father);
    daughter.setFather(father);
    daughter.setMother(mother);
    //
    HashMap<Human2, String> children = new LinkedHashMap<Human2, String>(2);
    children.put(son, "son");
    children.put(daughter, "daughter");
    father.setChildren(children);
    mother.setChildren(children);
    //

    Constructor constructor = new Constructor(Human2.class);
    TypeDescription humanDescription = new TypeDescription(Human2.class);
    humanDescription.putMapPropertyType("children", Human2.class, String.class);
    constructor.addTypeDescription(humanDescription);

    Yaml yaml = new Yaml(constructor);
    String output = yaml.dump(son);
    // System.out.println(output);
    String etalon = Util.getLocalResource("recursive/with-children-2.yaml");
    assertEquals(etalon, output);
    //
    Human2 son2 = (Human2) yaml.load(output);
    assertNotNull(son2);
    assertEquals("Son", son.getName());

    Human2 father2 = son2.getFather();
    assertEquals("Father", father2.getName());
    assertEquals("Mother", son2.getMother().getName());
    assertSame(father2, father2.getBankAccountOwner());
    assertSame(father2.getPartner(), son2.getMother());
    assertSame(father2, son2.getMother().getPartner());

    Map<Human2, String> children2 = father2.getChildren();
    assertEquals(2, children2.size());
    assertSame(father2.getPartner().getChildren(), children2);

    validateMapKeys(children2);
}
 
開發者ID:bmoliveira,項目名稱:snake-yaml,代碼行數:67,代碼來源:HumanTest.java


注:本文中的org.yaml.snakeyaml.TypeDescription.putMapPropertyType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。