org.yaml.snakeyaml.nodes.MappingNode Java Examples

The following examples show how to use org.yaml.snakeyaml.nodes.MappingNode. 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: CompactConstructor.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void construct2ndStep(Node node, Object object) {
    // Compact Object Notation may contain only one entry
    MappingNode mnode = (MappingNode) node;
    NodeTuple nodeTuple = mnode.getValue().iterator().next();

    Node valueNode = nodeTuple.getValueNode();

    if (valueNode instanceof MappingNode) {
        valueNode.setType(object.getClass());
        constructJavaBean2ndStep((MappingNode) valueNode, object);
    } else {
        // value is a list
        applySequence(object, constructSequence((SequenceNode) valueNode));
    }
}
 
Example #2
Source File: YamlLoadAsIssueTest.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Car construct(Node node) {
    Car car = new Car();
    MappingNode mapping = (MappingNode) node;
    List<NodeTuple> list = mapping.getValue();
    for (NodeTuple tuple : list) {
        String field = toScalarString(tuple.getKeyNode());
        if ("plate".equals(field)) {
            car.setPlate(toScalarString(tuple.getValueNode()));
        }
        if ("wheels".equals(field)) {
            SequenceNode snode = (SequenceNode) tuple.getValueNode();
            List<Wheel> wheels = (List<Wheel>) constructSequence(snode);
            car.setWheels(wheels);
        }
    }
    return car;
}
 
Example #3
Source File: FragmentComposer.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
@Override
public Node getSingleNode() {
    Node node = super.getSingleNode();
    if (!MappingNode.class.isAssignableFrom(node.getClass())) {
        throw new RuntimeException(
                "Document is not structured as expected.  Root element should be a map!");
    }
    MappingNode root = (MappingNode) node;
    for (NodeTuple tuple : root.getValue()) {
        Node keyNode = tuple.getKeyNode();
        if (ScalarNode.class.isAssignableFrom(keyNode.getClass())) {
            if (((ScalarNode) keyNode).getValue().equals(nodeName)) {
                return tuple.getValueNode();
            }
        }
    }
    throw new RuntimeException("Did not find key \"" + nodeName + "\" in document-level map");
}
 
Example #4
Source File: YamlConstructor.java    From Diorite with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Map<Object, Object> constructMapping(MappingNode node)
{
    Object collection;
    if (Map.class.isAssignableFrom(node.getType()))
    {
        collection = YamlCollectionCreator.createCollection(node.getType(), node.getValue().size());
    }
    else
    {
        collection = YamlCollectionCreator.createCollection(Map.class, node.getValue().size());
    }
    this.constructMapping2ndStep(node, (Map<Object, Object>) collection);
    return super.constructMapping(node);
}
 
Example #5
Source File: YamlDeserializationData.java    From Diorite with MIT License 6 votes vote down vote up
@Override
public Set<String> getKeys()
{
    if (this.node instanceof MappingNode)
    {
        List<NodeTuple> tuples = ((MappingNode) this.node).getValue();
        Set<String> result = new LinkedHashSet<>(tuples.size());
        for (NodeTuple tuple : tuples)
        {
            Node keyNode = tuple.getKeyNode();
            if (keyNode instanceof ScalarNode)
            {
                result.add(((ScalarNode) keyNode).getValue());
            }
        }
        return result;
    }
    return Collections.emptySet();
}
 
Example #6
Source File: BaseConstructor.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
    List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a Set", node.getStartMark(),
                        "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
            }
        }
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it into the set because it may have different hash after
             * initialization compared to clean just created one. And set of
             * course does not observe value hashCode changes.
             */
            sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
        } else {
            set.add(key);
        }
    }
}
 
Example #7
Source File: AutotesterAnchorGenerator.java    From AuTe-Framework with Apache License 2.0 6 votes vote down vote up
@Override
public String nextAnchor(Node node) {
    if (node instanceof MappingNode) {
        NodeTuple idNode = ((MappingNode) node).getValue()
                .stream()
                .filter(nodeTuple -> nodeTuple.getKeyNode() instanceof ScalarNode)
                .filter(nodeTuple -> "id".equals(((ScalarNode) nodeTuple.getKeyNode()).getValue()))
                .findAny()
                .orElse(null);
        if (idNode != null && idNode.getValueNode() instanceof ScalarNode) {
            String idValue = ((ScalarNode) idNode.getValueNode()).getValue();
            if (idValue != null) {
                return "objId" + idValue;
            }
        }
    }
    return "id" + (lastAnchorId++);
}
 
Example #8
Source File: BaseConstructor.java    From onedev with MIT License 6 votes vote down vote up
protected void constructSet2ndStep(MappingNode node, Set<Object> set) {
    List<NodeTuple> nodeValue = node.getValue();
    for (NodeTuple tuple : nodeValue) {
        Node keyNode = tuple.getKeyNode();
        Object key = constructObject(keyNode);
        if (key != null) {
            try {
                key.hashCode();// check circular dependencies
            } catch (Exception e) {
                throw new ConstructorException("while constructing a Set", node.getStartMark(),
                        "found unacceptable key " + key, tuple.getKeyNode().getStartMark(), e);
            }
        }
        if (keyNode.isTwoStepsConstruction()) {
            /*
             * if keyObject is created it 2 steps we should postpone putting
             * it into the set because it may have different hash after
             * initialization compared to clean just created one. And set of
             * course does not observe value hashCode changes.
             */
            sets2fill.add(0, new RecursiveTuple<Set<Object>, Object>(set, key));
        } else {
            set.add(key);
        }
    }
}
 
Example #9
Source File: BaseRepresenter.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
protected Node representMapping(Tag tag, Map<?, ?> mapping, Boolean flowStyle) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size());
    MappingNode node = new MappingNode(tag, value, flowStyle);
    representedObjects.put(objectToRepresent, node);
    boolean bestStyle = true;
    for (Map.Entry<?, ?> entry : mapping.entrySet()) {
        Node nodeKey = representData(entry.getKey());
        Node nodeValue = representData(entry.getValue());
        if (!(nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null)) {
            bestStyle = false;
        }
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(new NodeTuple(nodeKey, nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
 
Example #10
Source File: CompactConstructor.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
@Override
public void construct2ndStep(Node node, Object object) {
    // Compact Object Notation may contain only one entry
    MappingNode mnode = (MappingNode) node;
    NodeTuple nodeTuple = mnode.getValue().iterator().next();

    Node valueNode = nodeTuple.getValueNode();

    if (valueNode instanceof MappingNode) {
        valueNode.setType(object.getClass());
        constructJavaBean2ndStep((MappingNode) valueNode, object);
    } else {
        // value is a list
        applySequence(object, constructSequence((SequenceNode) valueNode));
    }
}
 
Example #11
Source File: AdvancedRepresenterTest.java    From waggle-dance with Apache License 2.0 6 votes vote down vote up
@Test
public void notNullMapProperty() {
  bean.setMapProperty(ImmutableMap.<String, Long>builder().put("first", 1L).put("second", 2L).build());
  Property property = new MethodProperty(getPropertyDescriptor("mapProperty"));
  NodeTuple nodeTuple = representer.representJavaBeanProperty(bean, property, bean.getMapProperty(), null);
  assertThat(nodeTuple, is(notNullValue()));
  assertThat(nodeTuple.getKeyNode(), is(instanceOf(ScalarNode.class)));
  assertThat(((ScalarNode) nodeTuple.getKeyNode()).getValue(), is("map-property"));
  assertThat(nodeTuple.getValueNode(), is(instanceOf(MappingNode.class)));
  assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().size(), is(2));
  assertThat(((MappingNode) nodeTuple.getValueNode()).getValue().get(0), is(instanceOf(NodeTuple.class)));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getKeyNode()).getValue(),
      is("first"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(0).getValueNode()).getValue(),
      is("1"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getKeyNode()).getValue(),
      is("second"));
  assertThat(((ScalarNode) ((MappingNode) nodeTuple.getValueNode()).getValue().get(1).getValueNode()).getValue(),
      is("2"));
}
 
Example #12
Source File: YamlDeserializationData.java    From Diorite with MIT License 6 votes vote down vote up
@Nullable
private Node getNode(Node node, String key)
{
    if (key.isEmpty())
    {
        return node;
    }
    if (node instanceof SequenceNode)
    {
        SequenceNode sequenceNode = (SequenceNode) node;
        List<Node> sequenceNodeValue = sequenceNode.getValue();
        int i = DioriteMathUtils.asInt(key, - 1);
        if ((i == - 1) || (i < sequenceNodeValue.size()))
        {
            return null;
        }
        return sequenceNodeValue.get(i);
    }
    if (node instanceof MappingNode)
    {
        return this.getNode((MappingNode) node, key);
    }
    return null;
}
 
Example #13
Source File: XmlBuildSpecMigrator.java    From onedev with MIT License 6 votes vote down vote up
private static Node migrateJobDependency(Element jobDependencyElement) {
	List<NodeTuple> tuples = new ArrayList<>();
	tuples.add(new NodeTuple(
			new ScalarNode(Tag.STR, "jobName"), 
			new ScalarNode(Tag.STR, jobDependencyElement.elementText("jobName").trim())));
	tuples.add(new NodeTuple(
			new ScalarNode(Tag.STR, "requireSuccessful"), 
			new ScalarNode(Tag.STR, jobDependencyElement.elementText("requireSuccessful").trim())));
	Element artifactsElement = jobDependencyElement.element("artifacts");
	if (artifactsElement != null) {
		tuples.add(new NodeTuple(
				new ScalarNode(Tag.STR, "artifacts"), 
				new ScalarNode(Tag.STR, artifactsElement.getText().trim())));
	}
	
	List<Node> paramSupplyNodes = migrateParamSupplies(jobDependencyElement.element("jobParams").elements());
	if (!paramSupplyNodes.isEmpty()) {
		tuples.add(new NodeTuple(
				new ScalarNode(Tag.STR, "jobParams"), 
				new SequenceNode(Tag.SEQ, paramSupplyNodes, FlowStyle.BLOCK)));
	}
	return new MappingNode(Tag.MAP, tuples, FlowStyle.BLOCK);
}
 
Example #14
Source File: YamlConstructMapping.java    From Diorite with MIT License 6 votes vote down vote up
protected Object createEmptyJavaBean(MappingNode node)
{
    try
    {
        /*
         * Using only default constructor. Everything else will be
         * initialized on 2nd step. If we do here some partial
         * initialization, how do we then track what need to be done on
         * 2nd step? I think it is better to get only object here (to
         * have it as reference for recursion) and do all other thing on
         * 2nd step.
         */
        java.lang.reflect.Constructor<?> c = node.getType().getDeclaredConstructor();
        c.setAccessible(true);
        return c.newInstance();
    }
    catch (Exception e)
    {
        throw new YAMLException(e);
    }
}
 
Example #15
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 #16
Source File: ValidationUtil.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 6 votes vote down vote up
public static int getLine(JsonNode error, Node yamlTree) {
    String path = getInstancePointer(error);

    if (path == null || path.isEmpty())
        return 1;

    path = path.substring(1, path.length());
    String[] strings = path.split("/");

    if (yamlTree instanceof MappingNode) {
        MappingNode mn = (MappingNode) yamlTree;

        Node findNode = findNode(mn, Arrays.asList(strings));
        if (findNode != null) {
            return findNode.getStartMark().getLine() + 1;
        }
    }

    return 1;
}
 
Example #17
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 #18
Source File: Constructor.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected Object createEmptyJavaBean(MappingNode node) {
    try {
        /**
         * Using only default constructor. Everything else will be
         * initialized on 2nd step. If we do here some partial
         * initialization, how do we then track what need to be done on
         * 2nd step? I think it is better to get only object here (to
         * have it as reference for recursion) and do all other thing on
         * 2nd step.
         */
        java.lang.reflect.Constructor<?> c = node.getType().getDeclaredConstructor();
        c.setAccessible(true);
        return c.newInstance();
    } catch (Exception e) {
        throw new YAMLException(e);
    }
}
 
Example #19
Source File: BaseRepresenter.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected Node representMapping(Tag tag, Map<?, ?> mapping, Boolean flowStyle) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size());
    MappingNode node = new MappingNode(tag, value, flowStyle);
    representedObjects.put(objectToRepresent, node);
    boolean bestStyle = true;
    for (Map.Entry<?, ?> entry : mapping.entrySet()) {
        Node nodeKey = representData(entry.getKey());
        Node nodeValue = representData(entry.getValue());
        if (!((nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null))) {
            bestStyle = false;
        }
        if (!((nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null))) {
            bestStyle = false;
        }
        value.add(new NodeTuple(nodeKey, nodeValue));
    }
    if (flowStyle == null) {
        if (defaultFlowStyle != FlowStyle.AUTO) {
            node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
        } else {
            node.setFlowStyle(bestStyle);
        }
    }
    return node;
}
 
Example #20
Source File: SkriptYamlConstructor.java    From skript-yaml with MIT License 6 votes vote down vote up
@Override
public Object construct(Node node) {
	final Map<Object, Object> values = constructMapping((MappingNode) node);

	String w = (String) values.get("world");
	Double x = (Double) values.get("x");
	Double y = (Double) values.get("y");
	Double z = (Double) values.get("z");
	Double yaw = (Double) values.get("yaw");
	Double pitch = (Double) values.get("pitch");

	if (w == null | x == null || y == null || z == null || yaw == null || pitch == null)
		return null;

	return new Location(Bukkit.getServer().getWorld(w), x, y, z, (float) yaw.doubleValue(),
			(float) pitch.doubleValue());
}
 
Example #21
Source File: SafeConstructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void construct2ndStep(Node node, Object object) {
    if (node.isTwoStepsConstruction()) {
        constructSet2ndStep((MappingNode) node, (Set<Object>) object);
    } else {
        throw new YAMLException("Unexpected recursive set structure. Node: " + node);
    }
}
 
Example #22
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Grab the property value, assume it's a relative path and prepend the bundle's directory to make it an
 * absolute path.
 * 
 * @param node
 * @return
 */
protected String getPath(Node node, String propertyName)
{
	String relativePath = null;
	if (node instanceof MappingNode)
	{
		MappingNode map = (MappingNode) node;
		List<NodeTuple> nodes = map.getValue();
		for (NodeTuple tuple : nodes)
		{
			Node keyNode = tuple.getKeyNode();
			if (keyNode instanceof ScalarNode)
			{
				ScalarNode scalar = (ScalarNode) keyNode;
				String valueOfKey = scalar.getValue();
				if (propertyName.equals(valueOfKey))
				{
					Node valueNode = tuple.getValueNode();
					if (valueNode instanceof ScalarNode)
					{
						ScalarNode scalarValue = (ScalarNode) valueNode;
						relativePath = scalarValue.getValue();
						break;
					}
				}
			}
		}
	}
	if (relativePath != null)
	{
		IPath pathObj = Path.fromOSString(relativePath);
		if (!pathObj.isAbsolute())
		{
			// Prepend the bundle directory.
			relativePath = new File(bundleDirectory, relativePath).getAbsolutePath();
		}
	}
	return relativePath;
}
 
Example #23
Source File: SkriptYamlConstructor.java    From skript-yaml with MIT License 5 votes vote down vote up
@Override
public Object construct(Node node) {
	final Map<Object, Object> values = constructMapping((MappingNode) node);
	String type = (String) values.get("type");
	String data = (String) values.get("data");
	if (type == null || data == null)
		return null;

	return new SkriptClass(type, data).deserialize();
}
 
Example #24
Source File: YamlOrderedSkipEmptyRepresenter.java    From flow-platform-x with Apache License 2.0 5 votes vote down vote up
@Override
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    MappingNode node = new MappingNode(tag, value, FlowStyle.BLOCK);
    representedObjects.put(javaBean, node);

    List<Property> orderProperties = new ArrayList<>(properties);
    orderProperties.sort(sorter);

    for (Property property : orderProperties) {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = memberValue == null ? null
            : classTags.get(memberValue.getClass());
        NodeTuple tuple = representJavaBeanProperty(javaBean, property, memberValue,
            customPropertyTag);
        if (tuple == null) {
            continue;
        }

        value.add(tuple);
    }

    return node;
}
 
Example #25
Source File: SafeConstructor.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public Object construct(Node node) {
    // Note: we do not check for duplicate keys, because it's too
    // CPU-expensive.
    Map<Object, Object> omap = new LinkedHashMap<Object, Object>();
    if (!(node instanceof SequenceNode)) {
        throw new ConstructorException("while constructing an ordered map",
                node.getStartMark(), "expected a sequence, but found " + node.getNodeId(),
                node.getStartMark());
    }
    SequenceNode snode = (SequenceNode) node;
    for (Node subnode : snode.getValue()) {
        if (!(subnode instanceof MappingNode)) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a mapping of length 1, but found "
                            + subnode.getNodeId(), subnode.getStartMark());
        }
        MappingNode mnode = (MappingNode) subnode;
        if (mnode.getValue().size() != 1) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a single mapping item, but found "
                            + mnode.getValue().size() + " items", mnode.getStartMark());
        }
        Node keyNode = mnode.getValue().get(0).getKeyNode();
        Node valueNode = mnode.getValue().get(0).getValueNode();
        Object key = constructObject(keyNode);
        Object value = constructObject(valueNode);
        omap.put(key, value);
    }
    return omap;
}
 
Example #26
Source File: SafeConstructor.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected void flattenMapping(MappingNode node) {
    // perform merging only on nodes containing merge node(s)
    if (node.isMerged()) {
        node.setValue(mergeNode(node, true, new HashMap<Object, Integer>(),
                new ArrayList<NodeTuple>()));
    }
}
 
Example #27
Source File: SafeConstructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public Object construct(Node node) {
    // Note: we do not check for duplicate keys, because it's too
    // CPU-expensive.
    Map<Object, Object> omap = new LinkedHashMap<Object, Object>();
    if (!(node instanceof SequenceNode)) {
        throw new ConstructorException("while constructing an ordered map",
                node.getStartMark(), "expected a sequence, but found " + node.getNodeId(),
                node.getStartMark());
    }
    SequenceNode snode = (SequenceNode) node;
    for (Node subnode : snode.getValue()) {
        if (!(subnode instanceof MappingNode)) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a mapping of length 1, but found "
                            + subnode.getNodeId(), subnode.getStartMark());
        }
        MappingNode mnode = (MappingNode) subnode;
        if (mnode.getValue().size() != 1) {
            throw new ConstructorException("while constructing an ordered map",
                    node.getStartMark(), "expected a single mapping item, but found "
                            + mnode.getValue().size() + " items", mnode.getStartMark());
        }
        Node keyNode = mnode.getValue().get(0).getKeyNode();
        Node valueNode = mnode.getValue().get(0).getValueNode();
        Object key = constructObject(keyNode);
        Object value = constructObject(valueNode);
        omap.put(key, value);
    }
    return omap;
}
 
Example #28
Source File: YamlProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<Object, Object> constructMapping(MappingNode node) {
	try {
		return super.constructMapping(node);
	}
	catch (IllegalStateException ex) {
		throw new ParserException("while parsing MappingNode",
				node.getStartMark(), ex.getMessage(), node.getEndMark());
	}
}
 
Example #29
Source File: SafeConstructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public Object construct(Node node) {
    if (node.isTwoStepsConstruction()) {
        return createDefaultMap();
    } else {
        return constructMapping((MappingNode) node);
    }
}
 
Example #30
Source File: SafeConstructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
protected void flattenMapping(MappingNode node) {
    // perform merging only on nodes containing merge node(s)
    if (node.isMerged()) {
        node.setValue(mergeNode(node, true, new HashMap<Object, Integer>(),
                new ArrayList<NodeTuple>()));
    }
}