org.yaml.snakeyaml.TypeDescription Java Examples
The following examples show how to use
org.yaml.snakeyaml.TypeDescription.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrayInGenericCollectionTest.java From snake-yaml with Apache License 2.0 | 6 votes |
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()); }
Example #2
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testGettingVLNodes() throws FileNotFoundException { InputStream cpFile = new FileInputStream(new File("src/main/resources/Testing/testVNFDTemplate.yaml")); Constructor constructor = new Constructor(VNFDTemplate.class); TypeDescription typeDescription = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); VNFDTemplate cpInput = yaml.loadAs(cpFile, VNFDTemplate.class); List<VLNodeTemplate> vlNodes = cpInput.getTopology_template().getVLNodes(); for (VLNodeTemplate n : vlNodes) { System.out.println(n.toString()); } }
Example #3
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testCreatingVNFDInstance() throws FileNotFoundException, NotFoundException { InputStream vnfdFile = new FileInputStream(new File("src/main/resources/Testing/testVNFDTemplate.yaml")); Constructor constructor = new Constructor(VNFDTemplate.class); TypeDescription typeDescription = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); VNFDTemplate vnfdInput = yaml.loadAs(vnfdFile, VNFDTemplate.class); TOSCAParser parser = new TOSCAParser(); VirtualNetworkFunctionDescriptor vnfd = parser.parseVNFDTemplate(vnfdInput); Gson gson = new Gson(); System.out.println(gson.toJson(vnfd)); }
Example #4
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testGettingCPNodes() throws FileNotFoundException { InputStream cpFile = new FileInputStream(new File("src/main/resources/Testing/testTopologyTemplate.yaml")); Constructor constructor = new Constructor(TopologyTemplate.class); TypeDescription typeDescription = new TypeDescription(TopologyTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); TopologyTemplate cpInput = yaml.loadAs(cpFile, TopologyTemplate.class); List<CPNodeTemplate> cpNodes = cpInput.getCPNodes(); for (CPNodeTemplate n : cpNodes) { System.out.println(n.toString()); } }
Example #5
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testTopologyTemplate() throws FileNotFoundException { InputStream cpFile = new FileInputStream(new File("src/main/resources/Testing/testTopologyTemplate.yaml")); Constructor constructor = new Constructor(TopologyTemplate.class); TypeDescription typeDescription = new TypeDescription(TopologyTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); TopologyTemplate cpInput = yaml.loadAs(cpFile, TopologyTemplate.class); System.out.println(cpInput.toString()); }
Example #6
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testVNFDServerIperf() throws NotFoundException, FileNotFoundException { InputStream vnfdFile = new FileInputStream(new File("src/main/resources/Testing/vnfd_server_iperf.yaml")); Constructor constructor = new Constructor(VNFDTemplate.class); TypeDescription typeDescription = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); VNFDTemplate vnfdInput = yaml.loadAs(vnfdFile, VNFDTemplate.class); TOSCAParser parser = new TOSCAParser(); VirtualNetworkFunctionDescriptor vnfd = parser.parseVNFDTemplate(vnfdInput); Gson gson = new Gson(); System.out.println(gson.toJson(vnfd)); }
Example #7
Source File: GodScreen.java From xibalba with MIT License | 6 votes |
private void updateAbilitiesGroup() { abilityGroup.clear(); abilityGroup.addActor(new Label("Abilities", Main.skin)); abilityGroup.addActor(new Label("", Main.skin)); GodData godData = godDataList.get(godSelected); Constructor constructor = new Constructor(Ability.class); constructor.addTypeDescription(new TypeDescription(Charm.class, "!Charm")); Yaml yaml = new Yaml(constructor); godData.abilities.forEach((String ability) -> { Ability details = (Ability) yaml.load(Main.abilitiesData.get(ability)); abilityGroup.addActor( new Label( createAbilityText(details), Main.skin) ); }); }
Example #8
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testNSDIperfTemplate() throws FileNotFoundException, NotFoundException { InputStream nsdFile = new FileInputStream(new File("src/main/resources/Testing/testNSDIperf.yaml")); Constructor constructor = new Constructor(NSDTemplate.class); TypeDescription typeDescription = new TypeDescription(NSDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); NSDTemplate nsdInput = yaml.loadAs(nsdFile, NSDTemplate.class); TOSCAParser parser = new TOSCAParser(); NetworkServiceDescriptor nsd = parser.parseNSDTemplate(nsdInput); Gson gson = new Gson(); System.out.println(gson.toJson(nsd)); }
Example #9
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testNSDIperfASTemplate() throws FileNotFoundException, NotFoundException { InputStream nsdFile = new FileInputStream(new File("src/main/resources/Testing/testNSDIperfAutoscaling.yaml")); Constructor constructor = new Constructor(NSDTemplate.class); TypeDescription typeDescription = new TypeDescription(NSDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); NSDTemplate nsdInput = yaml.loadAs(nsdFile, NSDTemplate.class); TOSCAParser parser = new TOSCAParser(); NetworkServiceDescriptor nsd = parser.parseNSDTemplate(nsdInput); Gson gson = new Gson(); System.out.println(gson.toJson(nsd)); }
Example #10
Source File: BaseConstructor.java From onedev with MIT License | 6 votes |
public BaseConstructor() { constructedObjects = new HashMap<Node, Object>(); recursiveObjects = new HashSet<Node>(); maps2fill = new ArrayList<RecursiveTuple<Map<Object, Object>, RecursiveTuple<Object, Object>>>(); sets2fill = new ArrayList<RecursiveTuple<Set<Object>, Object>>(); typeDefinitions = new HashMap<Class<? extends Object>, TypeDescription>(); typeTags = new HashMap<Tag, Class<? extends Object>>(); rootTag = null; explicitPropertyUtils = false; typeDefinitions.put(SortedMap.class, new TypeDescription(SortedMap.class, Tag.OMAP, TreeMap.class)); typeDefinitions.put(SortedSet.class, new TypeDescription(SortedSet.class, Tag.SET, TreeSet.class)); }
Example #11
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testMultipleVLs() throws FileNotFoundException, NotFoundException { InputStream nsdFile = new FileInputStream(new File("src/main/resources/Testing/tosca-ns-example.yaml")); Constructor constructor = new Constructor(NSDTemplate.class); TypeDescription typeDescription = new TypeDescription(NSDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); NSDTemplate nsdInput = yaml.loadAs(nsdFile, NSDTemplate.class); TOSCAParser parser = new TOSCAParser(); NetworkServiceDescriptor nsd = parser.parseNSDTemplate(nsdInput); Gson gson = new Gson(); System.out.println(gson.toJson(nsd)); }
Example #12
Source File: YamlFactory.java From waggle-dance with Apache License 2.0 | 6 votes |
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); }
Example #13
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testGettingVDUNodes() throws FileNotFoundException { InputStream cpFile = new FileInputStream(new File("src/main/resources/Testing/testTopologyTemplate.yaml")); Constructor constructor = new Constructor(TopologyTemplate.class); TypeDescription typeDescription = new TypeDescription(TopologyTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); TopologyTemplate cpInput = yaml.loadAs(cpFile, TopologyTemplate.class); List<VDUNodeTemplate> vduNodes = cpInput.getVDUNodes(); for (VDUNodeTemplate n : vduNodes) { System.out.println(n.toString()); } }
Example #14
Source File: TypeSafePriorityTest.java From snake-yaml with Apache License 2.0 | 6 votes |
/** * 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()); }
Example #15
Source File: YAMLToJavaDeserialisationUnitTest.java From tutorials with MIT License | 6 votes |
@Test public void whenLoadYAMLDocumentWithTypeDescription_thenLoadCorrectJavaObjectWithCorrectGenericType() { Constructor constructor = new Constructor(Customer.class); TypeDescription customTypeDescription = new TypeDescription(Customer.class); customTypeDescription.addPropertyParameters("contactDetails", Contact.class); constructor.addTypeDescription(customTypeDescription); Yaml yaml = new Yaml(constructor); InputStream inputStream = this.getClass() .getClassLoader() .getResourceAsStream("yaml/customer_with_contact_details.yaml"); Customer customer = yaml.load(inputStream); assertNotNull(customer); assertEquals("John", customer.getFirstName()); assertEquals("Doe", customer.getLastName()); assertEquals(31, customer.getAge()); assertNotNull(customer.getContactDetails()); assertEquals(2, customer.getContactDetails().size()); assertEquals("mobile", customer.getContactDetails() .get(0) .getType()); assertEquals("landline", customer.getContactDetails() .get(1) .getType()); }
Example #16
Source File: ArrayInGenericCollectionTest.java From snake-yaml with Apache License 2.0 | 6 votes |
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()); } }
Example #17
Source File: GlobalDirectivesTest.java From snake-yaml with Apache License 2.0 | 6 votes |
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()); }
Example #18
Source File: GlobalDirectivesTest.java From snake-yaml with Apache License 2.0 | 6 votes |
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()); }
Example #19
Source File: PerlTest.java From snake-yaml with Apache License 2.0 | 6 votes |
@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); }
Example #20
Source File: Human_WithArrayOfChildrenTest.java From snake-yaml with Apache License 2.0 | 6 votes |
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); }
Example #21
Source File: TypeSafeCollectionsTest.java From snake-yaml with Apache License 2.0 | 6 votes |
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); } }
Example #22
Source File: ChronixSparkLoader.java From chronix.spark with Apache License 2.0 | 6 votes |
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); }
Example #23
Source File: Utils.java From NFVO with Apache License 2.0 | 6 votes |
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."); } }
Example #24
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testVNFDTemplate() throws FileNotFoundException { InputStream vnfdFile = new FileInputStream(new File("src/main/resources/Testing/testVNFDTemplate.yaml")); Constructor constructor = new Constructor(VNFDTemplate.class); TypeDescription typeDescription = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); VNFDTemplate vnfdInput = yaml.loadAs(vnfdFile, VNFDTemplate.class); System.out.println(vnfdInput.toString()); }
Example #25
Source File: ToscaTest.java From NFVO with Apache License 2.0 | 6 votes |
@Test @Ignore public void testGetNodesFromVNFDTemplate() throws FileNotFoundException, NotFoundException { InputStream vnfdFile = new FileInputStream(new File("src/main/resources/Testing/testVNFDTemplate.yaml")); Constructor constructor = new Constructor(VNFDTemplate.class); TypeDescription typeDescription = new TypeDescription(VNFDTemplate.class); constructor.addTypeDescription(typeDescription); Yaml yaml = new Yaml(constructor); VNFDTemplate vnfdInput = yaml.loadAs(vnfdFile, VNFDTemplate.class); System.out.println(vnfdInput.getTopology_template().getVDUNodes()); System.out.println(vnfdInput.getTopology_template().getCPNodes()); System.out.println(vnfdInput.getTopology_template().getVNFNodes()); }
Example #26
Source File: ArrayTagsTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testLoadClassNoRoot() { Constructor constructor = new Constructor(new TypeDescription(CarWithArray.class)); Yaml yaml = new Yaml(constructor); CarWithArray car = (CarWithArray) yaml.load(Util .getLocalResource("constructor/car-no-root-class.yaml")); assertEquals("12-XP-F4", car.getPlate()); Wheel[] wheels = car.getWheels(); assertNotNull(wheels); assertEquals(5, wheels.length); }
Example #27
Source File: BundleCacher.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public BundleElementsConstructor(File bundleDirectory) { this.bundleDirectory = bundleDirectory; this.yamlConstructors.put(new Tag(SCOPE_SELECTOR_TAG), new ConstructScopeSelector()); this.yamlConstructors.put(new Tag("!ruby/regexp"), new ConstructRubyRegexp()); //$NON-NLS-1$ this.yamlConstructors.put(new Tag(REGEXP_TAG), new ConstructRubyRegexp()); this.yamlConstructors.put(new Tag(COMMAND_TAG), new ConstructCommandElement()); this.yamlConstructors.put(new Tag(ENVIRONMENT_TAG), new ConstructEnvironmentElement()); this.yamlConstructors.put(new Tag(CONTENT_ASSIST_TAG), new ConstructContentAssistElement()); this.yamlConstructors.put(new Tag(TEMPLATE_TAG), new ConstructTemplateElement()); this.yamlConstructors.put(new Tag(BundleElement.class), new ConstructBundleElement()); this.yamlConstructors.put(new Tag(MenuElement.class), new ConstructMenuElement()); this.yamlConstructors.put(new Tag(SnippetElement.class), new ConstructSnippetElement()); this.yamlConstructors.put(new Tag(SnippetCategoryElement.class), new ConstructSnippetCategoryElement()); this.yamlConstructors.put(new Tag(ContentAssistElement.class), new ConstructContentAssistElement()); this.yamlConstructors.put(new Tag(CommandElement.class), new ConstructCommandElement()); this.yamlConstructors.put(new Tag(TemplateElement.class), new ConstructTemplateElement()); this.yamlConstructors.put(new Tag(SmartTypingPairsElement.class), new ConstructSmartTypingPairsElement()); this.yamlConstructors.put(new Tag(ProjectTemplateElement.class), new ConstructProjectTemplateElement()); this.yamlConstructors.put(new Tag(ProjectSampleElement.class), new ConstructProjectSampleElement()); this.yamlConstructors.put(new Tag(EnvironmentElement.class), new ConstructEnvironmentElement()); this.yamlConstructors.put(new Tag(BuildPathElement.class), new ConstructBuildPathElement()); // Tell it that "children" field for MenuElement is a list of MenuElements TypeDescription menuDescription = new TypeDescription(MenuElement.class); menuDescription.putListPropertyType("children", MenuElement.class); //$NON-NLS-1$ addTypeDescription(menuDescription); }
Example #28
Source File: YAMLWriter.java From ServerListPlus with GNU General Public License v3.0 | 5 votes |
public void registerAlias(Class<?> clazz, String alias) { Preconditions.checkArgument(!Strings.isNullOrEmpty(alias), "empty alias"); Tag tag = new Tag('!' + alias); // Add tag to representer and constructor to "notify" them about the alias snakeYAML.getRepresenter().addClassTag(clazz, tag); snakeYAML.getConstructor().addTypeDescription(new TypeDescription(clazz, tag)); }
Example #29
Source File: ArrayTagsTest.java From snake-yaml with Apache License 2.0 | 5 votes |
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()); }
Example #30
Source File: ImplicitResolverTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public void testMain() { Map<String, String> config = new HashMap<String, String>(); config.put("user.home", "HOME"); Constructor constructor = new ConfigurationConstructor(config); constructor.addTypeDescription(new TypeDescription(TestBean.class, "!testbean")); Yaml yaml = new Yaml(constructor); yaml.addImplicitResolver(CFG, Pattern.compile("\\$\\([a-zA-Z\\d\\u002E\\u005F]+\\)"), "$"); TestBean bean = (TestBean) yaml.load("!testbean {myval: !cfg $(user.home)}"); // System.out.println(bean.toString()); assertEquals("Explicit tag must be respected", "HOME", bean.getMyval()); bean = (TestBean) yaml.load("!testbean {myval: $(user.home)}"); // System.out.println(bean.toString()); assertEquals("Implicit tag must be respected", "HOME", bean.getMyval()); }