org.yaml.snakeyaml.nodes.Tag Java Examples

The following examples show how to use org.yaml.snakeyaml.nodes.Tag. 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: YamlRepresenter.java    From multiapps with Apache License 2.0 6 votes vote down vote up
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
    if (ObjectUtils.isEmpty(propertyValue)) {
        return null;
    }
    Field field = getField(javaBean.getClass(), property.getName());
    String nodeName = field.isAnnotationPresent(YamlElement.class) ? field.getAnnotation(YamlElement.class)
                                                                          .value()
        : property.getName();

    if (field.isAnnotationPresent(YamlAdapter.class)) {
        return getAdaptedTuple(propertyValue, field, nodeName);
    }

    NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
    return new NodeTuple(representData(nodeName), defaultNode.getValueNode());
}
 
Example #2
Source File: XmlBuildSpecMigrator.java    From onedev with MIT License 6 votes vote down vote up
private static Node migrateDefaultMultiValueProvider(Element defaultMultiValueProviderElement) {
	List<NodeTuple> tuples = new ArrayList<>();
	String classTag = getClassTag(defaultMultiValueProviderElement.attributeValue("class"));
	Element scriptNameElement = defaultMultiValueProviderElement.element("scriptName");
	if (scriptNameElement != null) {
		tuples.add(new NodeTuple(
				new ScalarNode(Tag.STR, "scriptName"), 
				new ScalarNode(Tag.STR, scriptNameElement.getText().trim())));
	}
	Element valueElement = defaultMultiValueProviderElement.element("value");
	if (valueElement != null) {
		List<Node> valueItemNodes = new ArrayList<>();
		for (Element valueItemElement: valueElement.elements())
			valueItemNodes.add(new ScalarNode(Tag.STR, valueItemElement.getText().trim()));
		tuples.add(new NodeTuple(
				new ScalarNode(Tag.STR, "value"), 
				new SequenceNode(Tag.SEQ, valueItemNodes, FlowStyle.BLOCK)));
	}
	
	return new MappingNode(new Tag(classTag), tuples, FlowStyle.BLOCK);
}
 
Example #3
Source File: SafeConstructor.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
public SafeConstructor() {
    this.yamlConstructors.put(Tag.NULL, new ConstructYamlNull());
    this.yamlConstructors.put(Tag.BOOL, new ConstructYamlBool());
    this.yamlConstructors.put(Tag.INT, new ConstructYamlInt());
    this.yamlConstructors.put(Tag.FLOAT, new ConstructYamlFloat());
    this.yamlConstructors.put(Tag.BINARY, new ConstructYamlBinary());
    this.yamlConstructors.put(Tag.TIMESTAMP, new ConstructYamlTimestamp());
    this.yamlConstructors.put(Tag.OMAP, new ConstructYamlOmap());
    this.yamlConstructors.put(Tag.PAIRS, new ConstructYamlPairs());
    this.yamlConstructors.put(Tag.SET, new ConstructYamlSet());
    this.yamlConstructors.put(Tag.STR, new ConstructYamlStr());
    this.yamlConstructors.put(Tag.SEQ, new ConstructYamlSeq());
    this.yamlConstructors.put(Tag.MAP, new ConstructYamlMap());
    this.yamlConstructors.put(null, undefinedConstructor);
    this.yamlClassConstructors.put(NodeId.scalar, undefinedConstructor);
    this.yamlClassConstructors.put(NodeId.sequence, undefinedConstructor);
    this.yamlClassConstructors.put(NodeId.mapping, undefinedConstructor);
}
 
Example #4
Source File: RubyTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #5
Source File: PerlTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: Yaml.java    From java with Apache License 2.0 6 votes vote down vote up
@Override
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
  MappingNode node = super.representJavaBean(properties, javaBean);
  // Always set the tag to MAP so that SnakeYaml doesn't print out the class name as a tag.
  node.setTag(Tag.MAP);
  // Sort the output of our map so that we put certain keys, such as apiVersion, first.
  Collections.sort(
      node.getValue(),
      new Comparator<NodeTuple>() {
        @Override
        public int compare(NodeTuple a, NodeTuple b) {
          String nameA = ((ScalarNode) a.getKeyNode()).getValue();
          String nameB = ((ScalarNode) b.getKeyNode()).getValue();
          int intCompare =
              Integer.compare(getPropertyPosition(nameA), getPropertyPosition(nameB));
          if (intCompare != 0) {
            return intCompare;
          } else {
            return nameA.compareTo(nameB);
          }
        }
      });
  return node;
}
 
Example #7
Source File: SafeRepresenter.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
public Node representData(Object data) {
    Class<?> type = data.getClass().getComponentType();

    if (byte.class == type) {
        return representSequence(Tag.SEQ, asByteList(data), null);
    } else if (short.class == type) {
        return representSequence(Tag.SEQ, asShortList(data), null);
    } else if (int.class == type) {
        return representSequence(Tag.SEQ, asIntList(data), null);
    } else if (long.class == type) {
        return representSequence(Tag.SEQ, asLongList(data), null);
    } else if (float.class == type) {
        return representSequence(Tag.SEQ, asFloatList(data), null);
    } else if (double.class == type) {
        return representSequence(Tag.SEQ, asDoubleList(data), null);
    } else if (char.class == type) {
        return representSequence(Tag.SEQ, asCharList(data), null);
    } else if (boolean.class == type) {
        return representSequence(Tag.SEQ, asBooleanList(data), null);
    }

    throw new YAMLException("Unexpected primitive '"
            + type.getCanonicalName() + "'");
}
 
Example #8
Source File: Resolver.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected void addImplicitResolvers() {
    addImplicitResolver(Tag.BOOL, BOOL, "yYnNtTfFoO");
    /*
     * INT must be before FLOAT because the regular expression for FLOAT
     * matches INT (see issue 130)
     * http://code.google.com/p/snakeyaml/issues/detail?id=130
     */
    addImplicitResolver(Tag.INT, INT, "-+0123456789");
    addImplicitResolver(Tag.FLOAT, FLOAT, "-+0123456789.");
    addImplicitResolver(Tag.MERGE, MERGE, "<");
    addImplicitResolver(Tag.NULL, NULL, "~nN\0");
    addImplicitResolver(Tag.NULL, EMPTY, null);
    addImplicitResolver(Tag.TIMESTAMP, TIMESTAMP, "0123456789");
    addImplicitResolver(Tag.VALUE, VALUE, "=");
    // The following implicit resolver is only for documentation
    // purposes.
    // It cannot work
    // because plain scalars cannot start with '!', '&', or '*'.
    addImplicitResolver(Tag.YAML, YAML, "!&*");
}
 
Example #9
Source File: TestUtils.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
/**
 * Create master key file.
 *
 * @param file                   file instance
 * @param masterKeyConfiguration master key configuration
 */
public static void createMasterKeyFile(File file, MasterKeyConfiguration masterKeyConfiguration) {
    try {
        file.createNewFile();
        file.deleteOnExit();
        FileWriter fileWriter = new FileWriter(file);

        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);

        Representer representer = new Representer();
        representer.addClassTag(MasterKeyConfiguration.class, Tag.MAP);
        Yaml yaml = new Yaml(representer, options);

        yaml.setBeanAccess(BeanAccess.FIELD);
        yaml.dump(masterKeyConfiguration, fileWriter);
    } catch (IOException e) {
        Assert.fail("Failed to create temp password file");
    }
}
 
Example #10
Source File: GlobalDirectivesTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
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 #11
Source File: SafeRepresenter.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public SafeRepresenter() {
    this.nullRepresenter = new RepresentNull();
    this.representers.put(String.class, new RepresentString());
    this.representers.put(Boolean.class, new RepresentBoolean());
    this.representers.put(Character.class, new RepresentString());
    this.representers.put(byte[].class, new RepresentByteArray());
    
    Represent primitiveArray = new RepresentPrimitiveArray();
    representers.put(short[].class,   primitiveArray);
    representers.put(int[].class,     primitiveArray);
    representers.put(long[].class,    primitiveArray);
    representers.put(float[].class,   primitiveArray);
    representers.put(double[].class,  primitiveArray);
    representers.put(char[].class,    primitiveArray);
    representers.put(boolean[].class, primitiveArray);
    
    this.multiRepresenters.put(Number.class, new RepresentNumber());
    this.multiRepresenters.put(List.class, new RepresentList());
    this.multiRepresenters.put(Map.class, new RepresentMap());
    this.multiRepresenters.put(Set.class, new RepresentSet());
    this.multiRepresenters.put(Iterator.class, new RepresentIterator());
    this.multiRepresenters.put(new Object[0].getClass(), new RepresentArray());
    this.multiRepresenters.put(Date.class, new RepresentDate());
    this.multiRepresenters.put(Enum.class, new RepresentEnum());
    this.multiRepresenters.put(Calendar.class, new RepresentDate());
    classTags = new HashMap<Class<? extends Object>, Tag>();
}
 
Example #12
Source File: ContainerDataYaml.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
ContainerDataConstructor() {
  //Adding our own specific constructors for tags.
  // When a new Container type is added, we need to add yamlConstructor
  // for that
  this.yamlConstructors.put(
      KEYVALUE_YAML_TAG, new ConstructKeyValueContainerData());
  this.yamlConstructors.put(Tag.INT, new ConstructLong());
}
 
Example #13
Source File: YamlSerialization.java    From biomedicus with Apache License 2.0 5 votes vote down vote up
public static Yaml createYaml(BidirectionalDictionary bidirectionalDictionary) {
  Yaml yaml = new Yaml(constructor(bidirectionalDictionary), representer(bidirectionalDictionary));
  yaml.addImplicitResolver(new Tag("!cui"), CUI.CUI_PATTERN, "C");
  yaml.addImplicitResolver(new Tag("!tui"), TUI.TUI_PATTERN, "T");
  yaml.addImplicitResolver(new Tag("!sui"), SUI.SUI_PATTERN, "S");
  return yaml;
}
 
Example #14
Source File: Serialization.java    From Diorite with MIT License 5 votes vote down vote up
/**
 * Serialize a Java object into a YAML Node.
 *
 * @param data
 *         Java object to be Serialized to YAML
 *
 * @return YAML Node
 */
public Node toYamlNode(@Nullable Object data)
{
    Node represent = this.yaml().represent(data);
    if (data != null)
    {
        if (! (data instanceof Map) && ! (data instanceof Collection))
        {
            represent.setType(data.getClass());
            represent.setTag(new Tag(data.getClass()));
        }
    }
    return represent;
}
 
Example #15
Source File: ArrayInGenericCollectionTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testNoTags() {
    Yaml yaml2dump = new Yaml();
    yaml2dump.setBeanAccess(BeanAccess.FIELD);
    B data = createB();
    String dump = yaml2dump.dumpAs(data, Tag.MAP, FlowStyle.AUTO);
    // System.out.println(dump);
    assertEquals("meta:\n- [whatever]\n- [something, something else]\n", dump);
    //
    Constructor constr = new Constructor(B.class);
    Yaml yaml2load = new Yaml(constr);
    yaml2load.setBeanAccess(BeanAccess.FIELD);
    B loaded = (B) yaml2load.load(dump);

    Assert.assertArrayEquals(data.meta.toArray(), loaded.meta.toArray());
}
 
Example #16
Source File: Representer.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
/**
 * Represent one JavaBean property.
 *
 * @param javaBean
 *            - the instance to be represented
 * @param property
 *            - the property of the instance
 * @param propertyValue
 *            - value to be represented
 * @param customTag
 *            - user defined Tag
 * @return NodeTuple to be used in a MappingNode. Return null to skip the
 *         property
 */
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
        Object propertyValue, Tag customTag) {
    ScalarNode nodeKey = (ScalarNode) representData(property.getName());
    // the first occurrence of the node must keep the tag
    boolean hasAlias = this.representedObjects.containsKey(propertyValue);

    Node nodeValue = representData(propertyValue);

    if (propertyValue != null && !hasAlias) {
        NodeId nodeId = nodeValue.getNodeId();
        if (customTag == null) {
            if (nodeId == NodeId.scalar) {
                if (propertyValue instanceof Enum<?>) {
                    nodeValue.setTag(Tag.STR);
                }
            } else {
                if (nodeId == NodeId.mapping) {
                    if (property.getType() == propertyValue.getClass()) {
                        if (!(propertyValue instanceof Map<?, ?>)) {
                            if (!nodeValue.getTag().equals(Tag.SET)) {
                                nodeValue.setTag(Tag.MAP);
                            }
                        }
                    }
                }
                checkGlobalTag(property, nodeValue, propertyValue);
            }
        }
    }

    return new NodeTuple(nodeKey, nodeValue);
}
 
Example #17
Source File: SerializerTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public void testSerializerIsNotOpened2() throws IOException {
    try {
        serializer.serialize(new ScalarNode(new Tag("!foo"), "bar", null, null, (char) 0));
        fail();
    } catch (RuntimeException e) {
        assertEquals("serializer is not opened", e.getMessage());
    }
}
 
Example #18
Source File: AbstractPluginDescriptorUpgradeOperation.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(final String site) throws UpgradeException {
    Path descriptorFile = getRepositoryPath(site).getParent().resolve(descriptorPath);
    if (Files.notExists(descriptorFile)) {
        logger.info("Plugin descriptor file not found for site {0}", site);
        return;
    }
    try (Reader reader = Files.newBufferedReader(descriptorFile)) {
        PluginDescriptor descriptor = descriptorReader.read(reader);
        if (descriptor.getDescriptorVersion().equals(descriptorVersion)) {
            logger.info("Plugin descriptor already update for site " + site);
            return;
        }
        logger.info("Updating plugin descriptor for site " + site);
        doPluginDescriptorUpdates(descriptor);
        descriptor.setDescriptorVersion(descriptorVersion);

        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
        options.setPrettyFlow(true);
        Yaml yaml = new Yaml(new Representer() {
            @Override
            protected NodeTuple representJavaBeanProperty(final Object javaBean, final Property property,
                                                          final Object propertyValue, final Tag customTag) {
                if (propertyValue != null) {
                    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
                }
                return null;
            }
        }, options);
        String content = yaml.dumpAsMap(descriptor);

        writeToRepo(site, descriptorPath, new ByteArrayInputStream(content.getBytes()));

        commitAllChanges(site);
    } catch (Exception e) {
        throw new UpgradeException("Plugin descriptor can't be read for site " + site);
    }
}
 
Example #19
Source File: BaseRepresenter.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
protected Node representScalar(Tag tag, String value, Character style) {
    if (style == null) {
        style = this.defaultScalarStyle;
    }
    Node node = new ScalarNode(tag, value, null, null, style);
    return node;
}
 
Example #20
Source File: Representer.java    From Diorite with MIT License 5 votes vote down vote up
private void resetTag(Class<?> type, Node node)
{
    Tag tag = node.getTag();
    if (tag.matches(type))
    {
        if (Enum.class.isAssignableFrom(type))
        {
            node.setTag(Tag.STR);
        }
        else
        {
            node.setTag(Tag.MAP);
        }
    }
}
 
Example #21
Source File: SkriptYamlRepresenter.java    From skript-yaml with MIT License 5 votes vote down vote up
@SuppressWarnings({ "unchecked" })
public <T> T representMapping(Tag tag, Map<?, ?> mapping) {
	if (SkriptYaml.getInstance().getServerVersion() >= 13) {
		return (T) representMapping(tag, mapping, FlowStyle.BLOCK);
	} else {
		T node = null;
           try {
   			node = (T) representMappingMethod.invoke(this, tag, mapping, null);
           } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
           	e.printStackTrace();
           }
		return (T) node;
	}
}
 
Example #22
Source File: Yaml.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private void dumpAll(Iterator<? extends Object> data, Writer output, Tag rootTag) {
    Serializer serializer = new Serializer(new Emitter(output, dumperOptions), resolver,
            dumperOptions, rootTag);
    try {
        serializer.open();
        while (data.hasNext()) {
            Node node = representer.represent(data.next());
            serializer.serialize(node);
        }
        serializer.close();
    } catch (java.io.IOException e) {
        throw new YAMLException(e);
    }
}
 
Example #23
Source File: YamlTagResolver.java    From digdag with Apache License 2.0 5 votes vote down vote up
@Override
public void addImplicitResolver(Tag tag, Pattern regexp, String first)
{
    // This method is called by constructor through addImplicitResolvers
    // to setup default implicit resolvers.

    if (tag.equals(Tag.FLOAT)) {
        super.addImplicitResolver(tag, FLOAT_EXCEPTING_ZERO_START, first);
    }
    else if (tag.equals(Tag.INT)) {
        // This solves some unexpected behavior that snakeyaml
        // deserializes "10:00:00" to 3600.
        // See also org.yaml.snakeyaml.constructor.SafeConstructor.ConstructYamlInt
        super.addImplicitResolver(tag, INT_EXCEPTING_COLON, first);
    }
    else if (tag.equals(Tag.BOOL)) {
        // use stricter rule (reject 'On', 'Off', 'Yes', 'No')
        super.addImplicitResolver(Tag.BOOL, Pattern.compile("^(?:[Tt]rue|[Ff]alse)$"), "TtFf");
    }
    else if (tag.equals(Tag.TIMESTAMP)) {
        // This solves some unexpected behavior that snakeyaml
        // deserializes "2015-01-01 00:00:00" to java.util.Date
        // but jackson serializes java.util.Date to an integer.
        // See also org.yaml.snakeyaml.constructor.SafeConstructor.ConstructYamlTimestamp
        return;
    }
    else {
        super.addImplicitResolver(tag, regexp, first);
    }
}
 
Example #24
Source File: ModelConstructor.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
public ModelConstructor() {
    super(Mapping.class, ModelConstructor.class.getClassLoader());

    this.yamlConstructors.put(Tag.BOOL, ConstructScalar);
    this.yamlConstructors.put(Tag.INT, ConstructScalar);
    this.yamlConstructors.put(Tag.STR, ConstructScalar);

}
 
Example #25
Source File: YamlBase64Test.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
/**
 * Redefine the !!binary global tag in a way that it ignores all the white
 * spaces to be able to use literal scalar
 */
@SuppressWarnings("unchecked")
public void testRedefineBinaryTag() throws IOException {
    Yaml yaml = new Yaml(new SpecialContructor(Tag.BINARY));
    InputStream inputStream = YamlBase64Test.class
            .getResourceAsStream("/issues/issue99-base64_literal.yaml");
    Map<String, Object> bean = (Map<String, Object>) yaml.load(inputStream);
    byte[] jpeg = (byte[]) bean.get("jpegPhoto");
    checkBytes(jpeg);
    inputStream.close();
}
 
Example #26
Source File: Example2_24Test.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public Node representData(Object data) {
    Circle circle = (Circle) data;
    Map<String, Object> map = new TreeMap<String, Object>();
    map.put("center", circle.getCenter());
    map.put("radius", circle.getRadius());
    return representMapping(new Tag("!circle"), map, Boolean.FALSE);
}
 
Example #27
Source File: SkriptYamlRepresenter.java    From skript-yaml with MIT License 5 votes vote down vote up
public SkriptYamlRepresenter() {
	this.nullRepresenter = new Represent() {
		@Override
		public Node representData(Object o) {
			return representScalar(Tag.NULL, "");
		}
	};

	this.representers.put(SkriptClass.class, new RepresentSkriptClass());
	this.representers.put(ItemType.class, new RepresentSkriptItemType());
	this.representers.put(Slot.class, new RepresentSkriptSlot());
	this.representers.put(Date.class, new RepresentSkriptDate());
	this.representers.put(Time.class, new RepresentSkriptTime());
	this.representers.put(Timespan.class, new RepresentSkriptTimespan());
	this.representers.put(Color.class, new RepresentSkriptColor());
	this.representers.put(WeatherType.class, new RepresentSkriptWeather());

	this.representers.put(Vector.class, new RepresentVector());
	this.representers.put(Location.class, new RepresentLocation());

	this.multiRepresenters.put(ConfigurationSerializable.class, new RepresentConfigurationSerializable());

	for (Class<?> c : representers.keySet()) {
		if (c != null) {
			String name = c.getSimpleName();
			if (!representedClasses.contains(name))
				representedClasses.add(name);
		}
	}
}
 
Example #28
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
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 #29
Source File: SafeRepresenter.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public Node representData(Object data) {
    Map<Object, Object> value = new LinkedHashMap<Object, Object>();
    Set<Object> set = (Set<Object>) data;
    for (Object key : set) {
        value.put(key, null);
    }
    return representMapping(getTag(data.getClass(), Tag.SET), value, null);
}
 
Example #30
Source File: PropOrderInfluenceWhenAliasedInGenericCollectionTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
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);
}