本文整理匯總了Java中org.yaml.snakeyaml.TypeDescription類的典型用法代碼示例。如果您正苦於以下問題:Java TypeDescription類的具體用法?Java TypeDescription怎麽用?Java TypeDescription使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TypeDescription類屬於org.yaml.snakeyaml包,在下文中一共展示了TypeDescription類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newYaml
import org.yaml.snakeyaml.TypeDescription; //導入依賴的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);
}
示例2: testLocalTag
import org.yaml.snakeyaml.TypeDescription; //導入依賴的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());
}
示例3: testLoadList2
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
/**
* explicit TypeDescription is more important then runtime class (which may
* be an interface)
*/
public void testLoadList2() {
String output = Util.getLocalResource("examples/list-bean-3.yaml");
// System.out.println(output);
TypeDescription descr = new TypeDescription(ListBean.class);
descr.putListPropertyType("developers", Developer.class);
Yaml beanLoader = new Yaml(new Constructor(descr));
ListBean parsed = beanLoader.loadAs(output, ListBean.class);
assertNotNull(parsed);
List<Human> developers = parsed.getDevelopers();
assertEquals(2, developers.size());
assertEquals("Committer must be recognised.", Developer.class, developers.get(0).getClass());
Developer fred = (Developer) developers.get(0);
assertEquals("Fred", fred.getName());
assertEquals("creator", fred.getRole());
Developer john = (Developer) developers.get(1);
assertEquals("John", john.getName());
assertEquals("committer", john.getRole());
}
示例4: testChildrenArray
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
public void testChildrenArray() {
Constructor constructor = new Constructor(Human_WithArrayOfChildren.class);
TypeDescription HumanWithChildrenArrayDescription = new TypeDescription(
Human_WithArrayOfChildren.class);
HumanWithChildrenArrayDescription.putListPropertyType("children",
Human_WithArrayOfChildren.class);
constructor.addTypeDescription(HumanWithChildrenArrayDescription);
Human_WithArrayOfChildren son = createSon();
Yaml yaml = new Yaml(constructor);
String output = yaml.dump(son);
// System.out.println(output);
String etalon = Util.getLocalResource("recursive/with-childrenArray.yaml");
assertEquals(etalon, output);
//
Human_WithArrayOfChildren son2 = (Human_WithArrayOfChildren) yaml.load(output);
checkSon(son2);
}
示例5: testJavaBeanWithTypeDescription
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public void testJavaBeanWithTypeDescription() {
Constructor c = new CustomBeanConstructor();
TypeDescription descr = new TypeDescription(CodeBean.class, new Tag(
"!de.oddb.org,2007/ODDB::Util::Code"));
c.addTypeDescription(descr);
Yaml yaml = new Yaml(c);
String input = Util.getLocalResource("issues/issue56-1.yaml");
int counter = 0;
for (Object obj : yaml.loadAll(input)) {
// System.out.println(obj);
Map<String, Object> map = (Map<String, Object>) obj;
Integer oid = (Integer) map.get("oid");
assertTrue(oid > 10000);
counter++;
}
assertEquals(4, counter);
assertEquals(55, CodeBean.counter);
}
示例6: 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());
}
}
示例7: testArrayAsListValueWithTypeDespriptor
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
public void testArrayAsListValueWithTypeDespriptor() {
Yaml yaml2dump = new Yaml();
yaml2dump.setBeanAccess(BeanAccess.FIELD);
B data = createB();
String dump = yaml2dump.dump(data);
// System.out.println(dump);
TypeDescription aTypeDescr = new TypeDescription(B.class);
aTypeDescr.putListPropertyType("meta", String[].class);
Constructor c = new Constructor();
c.addTypeDescription(aTypeDescr);
Yaml yaml2load = new Yaml(c);
yaml2load.setBeanAccess(BeanAccess.FIELD);
B loaded = (B) yaml2load.load(dump);
Assert.assertArrayEquals(data.meta.toArray(), loaded.meta.toArray());
}
示例8: testDirectives
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
public void testDirectives() {
String input = Util.getLocalResource("issues/issue149-losing-directives.yaml");
// System.out.println(input);
Constructor constr = new Constructor();
TypeDescription description = new TypeDescription(ComponentBean.class, new Tag(
"tag:ualberta.ca,2012:" + 29));
constr.addTypeDescription(description);
Yaml yaml = new Yaml(constr);
Iterator<Object> parsed = yaml.loadAll(input).iterator();
ComponentBean bean1 = (ComponentBean) parsed.next();
assertEquals(0, bean1.getProperty1());
assertEquals("aaa", bean1.getProperty2());
ComponentBean bean2 = (ComponentBean) parsed.next();
assertEquals(3, bean2.getProperty1());
assertEquals("bbb", bean2.getProperty2());
assertFalse(parsed.hasNext());
}
示例9: testDirectives2
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
public void testDirectives2() {
String input = Util.getLocalResource("issues/issue149-losing-directives-2.yaml");
// System.out.println(input);
Constructor constr = new Constructor();
TypeDescription description = new TypeDescription(ComponentBean.class, new Tag(
"tag:ualberta.ca,2012:" + 29));
constr.addTypeDescription(description);
Yaml yaml = new Yaml(constr);
Iterator<Object> parsed = yaml.loadAll(input).iterator();
ComponentBean bean1 = (ComponentBean) parsed.next();
assertEquals(0, bean1.getProperty1());
assertEquals("aaa", bean1.getProperty2());
ComponentBean bean2 = (ComponentBean) parsed.next();
assertEquals(3, bean2.getProperty1());
assertEquals("bbb", bean2.getProperty2());
assertFalse(parsed.hasNext());
}
示例10: 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);
}
}
示例11: testLoadClassTag
import org.yaml.snakeyaml.TypeDescription; //導入依賴的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);
}
示例12: load
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
@Override
public Object load(AssetInfo assetInfo) throws IOException {
Constructor constructor = new Constructor();
InputStream file = assetInfo.openStream();
Yaml yaml = new Yaml(constructor);
constructor.addTypeDescription(new TypeDescription(Theme.class, "!theme"));
try {
Theme theme = (Theme) yaml.load(file);
String path = theme.getPath();
if (path == null || path.equals("")) {
theme.setPath(folderName(assetInfo.getKey().getName()) + "/" + theme.getName() + ".css");
} else if (!path.startsWith("/")) {
theme.setPath(folderName(assetInfo.getKey().getName()) + "/" + path);
}
return theme;
} finally {
file.close();
}
}
示例13: registerTypes
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
private void registerTypes(Constructor constructor) {
// Standard controls
constructor.addTypeDescription(new TypeDescription(PanelLayoutPart.class, "!panel"));
constructor.addTypeDescription(new TypeDescription(LabelLayoutPart.class, "!label"));
constructor.addTypeDescription(new TypeDescription(CheckBoxLayoutPart.class, "!checkBox"));
constructor.addTypeDescription(new TypeDescription(DefaultButtonLayoutPart.class, "!button"));
constructor.addTypeDescription(new TypeDescription(SplitPaneLayoutPart.class, "!splitPanel"));
constructor.addTypeDescription(new TypeDescription(ScrollPanelLayoutPart.class, "!scrollPanel"));
constructor.addTypeDescription(new TypeDescription(ContainerLayoutPart.class, "!container"));
constructor.addTypeDescription(new TypeDescription(FrameLayoutPart.class, "!frame"));
constructor.addTypeDescription(new TypeDescription(TextFieldLayoutPart.class, "!textField"));
constructor.addTypeDescription(new TypeDescription(PasswordLayoutPart.class, "!password"));
constructor.addTypeDescription(new TypeDescription(XHTMLLabelLayoutPart.class, "!xhtmlLabel"));
// Layouts
constructor.addTypeDescription(new TypeDescription(FillLayoutLayoutPart.class, "!fillLayout"));
constructor.addTypeDescription(new TypeDescription(BorderLayoutLayoutPart.class, "!borderLayout"));
constructor.addTypeDescription(new TypeDescription(MigLayoutLayoutPart.class, "!migLayout"));
// Custom
ServiceLoader<LayoutPartRegisterable> parts = ServiceLoader.load(LayoutPartRegisterable.class);
for (LayoutPartRegisterable part : parts) {
part.register(constructor);
}
}
示例14: 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);
}
示例15: bytesToNSDTemplate
import org.yaml.snakeyaml.TypeDescription; //導入依賴的package包/類
public static NSDTemplate bytesToNSDTemplate(ByteArrayOutputStream b) throws BadFormatException {
Constructor constructor = new Constructor(NSDTemplate.class);
TypeDescription projectDesc = new TypeDescription(NSDTemplate.class);
constructor.addTypeDescription(projectDesc);
Yaml yaml = new Yaml(constructor);
try {
return yaml.loadAs(new ByteArrayInputStream(b.toByteArray()), NSDTemplate.class);
} catch (Exception e) {
log.error(e.getLocalizedMessage());
throw new BadFormatException(
"Problem parsing the descriptor. Check if yaml is formatted correctly.");
}
}