org.yaml.snakeyaml.nodes.NodeTuple Java Examples

The following examples show how to use org.yaml.snakeyaml.nodes.NodeTuple. 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: BaseConstructor.java    From orion.server with Eclipse Public License 1.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 #2
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 #3
Source File: StrictSafeConstructor.java    From digdag with Apache License 2.0 6 votes vote down vote up
private void validateKeys(MappingNode node)
{
    Map<String, Long> keyCounts = node.getValue().stream()
            .map(NodeTuple::getKeyNode)
            .filter(n -> n instanceof ScalarNode)
            .map(ScalarNode.class::cast)
            .filter(n -> !"!include".equals(n.getTag().getValue()))  // exclude !include tag
            .collect(Collectors.groupingBy(ScalarNode::getValue, Collectors.counting()));
    List<String> duplicatedKeys = keyCounts.entrySet().stream()
            .filter(it -> it.getValue() > 1)
            .map(Map.Entry<String, Long>::getKey)
            .collect(Collectors.toList());
    if (!duplicatedKeys.isEmpty()) {
        throw new DuplicateKeyYAMLException(duplicatedKeys);
    }
}
 
Example #4
Source File: YamlDeserializationData.java    From Diorite with MIT License 6 votes vote down vote up
@Nullable
private Node getNode(MappingNode node, String key, boolean remove)
{
    for (Iterator<NodeTuple> iterator = node.getValue().iterator(); iterator.hasNext(); )
    {
        NodeTuple tuple = iterator.next();
        Node keyNode = tuple.getKeyNode();
        if (! (keyNode instanceof ScalarNode))
        {
            return null;
        }
        if (key.equals(((ScalarNode) keyNode).getValue()))
        {
            if (remove)
            {
                iterator.remove();
            }
            return tuple.getValueNode();
        }
    }
    return null;
}
 
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: 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 #7
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
		Tag customTag)
{
	if (javaBean instanceof AbstractElement)
	{
		if ("path".equals(property.getName()) || "buildPath".equals(property.getName())) //$NON-NLS-1$ //$NON-NLS-2$
		{
			String path = (String) propertyValue;
			IPath relative = Path.fromOSString(path).makeRelativeTo(
					Path.fromOSString(bundleDirectory.getAbsolutePath()));
			propertyValue = relative.toOSString();
		}
	}
	return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
 
Example #8
Source File: YamlDeserializationData.java    From Diorite with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <K, T, M extends Map<K, T>> void getMap(String key, Function<String, K> keyMapper, Class<T> type, M map)
{
    Node node = this.getNode(this.node, key);
    if (! (node instanceof MappingNode))
    {
        throw new DeserializationException(type, this, "Can't find valid value for key: " + key);
    }
    MappingNode mappingNode = (MappingNode) node;
    Tag typeTag = new Tag(type);
    for (NodeTuple tuple : mappingNode.getValue())
    {
        Node keyNode = tuple.getKeyNode();
        keyNode.setTag(Tag.STR);
        K keyObj = keyMapper.apply(this.constructor.constructObject(keyNode).toString());

        Node valueNode = tuple.getValueNode();
        if (type != Object.class)
        {
            valueNode.setTag(typeTag);
        }

        map.put(keyObj, (T) this.constructor.constructObject(valueNode));
    }
}
 
Example #9
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 #10
Source File: YamlTester.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Object construct(Node node) {
    if(!(node instanceof MappingNode)) {
        fail("The value of the !select-engine tag must be a map" + "\nGot: " + node);
    }
    String matchingKey = null;
    Object result = null;
    for(NodeTuple tuple : ((MappingNode)node).getValue()) {
        Node keyNode = tuple.getKeyNode();
        if(!(keyNode instanceof ScalarNode)) {
            fail("The key in a !select-engine map must be a scalar" + "\nGot: " + constructObject(keyNode));
        }
        String key = ((ScalarNode)keyNode).getValue();
        if(IT_ENGINE.equals(key) || (matchingKey == null && ALL_ENGINE.equals(key))) {
            matchingKey = key;
            result = constructObject(tuple.getValueNode());
        }
    }
    if(matchingKey != null) {
        LOG.debug("Select engine: '{}' => '{}'", matchingKey, result);
        return result;
    } else {
        LOG.debug("Select engine: no match");
        return null;
    }
}
 
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: 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 #13
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 #14
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 #15
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 #16
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 #17
Source File: SkipBeanTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
        Object propertyValue, Tag customTag) {
    if (propertyValue == null) {
        return null;
    } else {
        return super
                .representJavaBeanProperty(javaBean, property, propertyValue, customTag);
    }
}
 
Example #18
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 #19
Source File: SkipEmptyRepresenter.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
    if (isInvalidType(property, propertyValue)) {
        return null;
    }
    return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
}
 
Example #20
Source File: YamlNodeReader.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
private void handleMessageField(ConfigSource.Builder builder, FieldDescriptor field, Node value,
    String path){
  if (field.isMapField()) {
    MappingNode map = NodeConverterUtils.expectMap(helper, field, value);
    FieldDescriptor keyField = field.getMessageType().getFields().get(0);
    FieldDescriptor valueField = field.getMessageType().getFields().get(1);
    boolean isNested =
        field.getMessageType().getFields().get(1).getType() == FieldDescriptor.Type.MESSAGE;
    for (NodeTuple entry : map.getValue()) {

      Object keyObj = NodeConverterUtils.convert(helper, keyField, entry.getKeyNode());
      if (keyObj == null) {
        continue;
      }
      if (isNested) {
        String nestedPath = appendToPath(path, keyObj);
        helper.checkAndAddPath(nestedPath, value, field);
        builder.withBuilder(field, keyObj, new ReadNodeBuildAction(helper, entry.getValueNode(),
            appendToPath(nestedPath, keyObj)));
      } else {
        Object valueObj = NodeConverterUtils.convert(helper, valueField, entry.getValueNode());
        if (valueObj != null) {
          builder.setValue(field, keyObj, valueObj, helper.getLocation(entry.getValueNode()));
        }
      }
    }
  } else if (field.isRepeated()) {
    SequenceNode list = NodeConverterUtils.expectList(helper, field, value);
    int index = 0;
    for (Node elem : list.getValue()) {
      String indexedPath = String.format("%s[%s]", path, index++);
      builder.withAddedBuilder(field, new ReadNodeBuildAction(helper, elem, indexedPath));
    }
  } else {
    builder.withBuilder(field, new ReadNodeBuildAction(helper, value, path));
  }
  addExplicitLocationField(builder, field, value);
}
 
Example #21
Source File: YamlRepresenter.java    From multiapps with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private NodeTuple getAdaptedTuple(Object propertyValue, Field field, String nodeName) {
    Class<? extends YamlConverter<?, ?>> converterClass = field.getAnnotation(YamlAdapter.class)
                                                               .value();
    try {
        YamlConverter<Object, ?> converter = (YamlConverter<Object, ?>) converterClass.newInstance();
        Object converted = converter.convert(propertyValue);
        return new NodeTuple(representData(nodeName), represent(converted));
    } catch (InstantiationException | IllegalAccessException e) {
        throw new IllegalStateException(e);
    }
}
 
Example #22
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>()));
    }
}
 
Example #23
Source File: ProjectConfigurator.java    From smart-testing with Apache License 2.0 5 votes vote down vote up
private void dumpConfiguration(Path configFilePath) {
    DumperOptions options = new DumperOptions();
    options.setDefaultFlowStyle(DumperOptions.FlowStyle.FLOW);

    Representer representer = new Representer() {
        @Override
        protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
            Tag customTag) {
            // if value of property is null, ignore it.
            if (propertyValue == null) {
                return null;
            } else {
                return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
            }
        }
    };

    representer.addClassTag(Configuration.class, Tag.MAP);

    Yaml yaml = new Yaml(representer, options);
    String config = yaml.dump(configuration);

    for (TestExecutionPlannerFactory factory : new JavaSPILoader().all(TestExecutionPlannerFactory.class)) {
        StrategyConfiguration strategyConfig = factory.strategyConfiguration();
        config = config.replaceAll("!!" + strategyConfig.getClass().getName(), strategyConfig.name() + ":");
    }
    try {
        Files.write(configFilePath, config.getBytes());
    } catch (IOException e) {
        throw new RuntimeException("Failed to dump configuration in file " + configFilePath, e);
    }
}
 
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: GenerateTestPlanCommand.java    From testgrid with Apache License 2.0 5 votes vote down vote up
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue,
        Tag customTag) {
    // if value of property is null, ignore it.
    if (propertyValue == null) {
        return null;
    } else {
        return super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
    }
}
 
Example #26
Source File: ManifestParser.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private void addChild(NodeTuple tuple, ManifestParseTree parent) throws ParserException {
	ManifestParseTree keyNode = new ManifestParseTree();
	Node tupleKeyNode = tuple.getKeyNode();
	int lineNumber = tupleKeyNode.getStartMark().getLine() + 1;
	if (tupleKeyNode.getNodeId() != NodeId.scalar) {
		throw new ParserException(NLS.bind(ManifestConstants.UNSUPPORTED_TOKEN_ERROR, lineNumber), lineNumber);
	}
	keyNode.setLabel(((ScalarNode) tupleKeyNode).getValue());
	keyNode.setLineNumber(lineNumber);
	keyNode.setParent(parent);
	parent.getChildren().add(keyNode);
	addChild(tuple.getValueNode(), keyNode);
}
 
Example #27
Source File: StaticFieldsTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@Override
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    MappingNode node = super.representJavaBean(properties, javaBean);
    if (javaBean instanceof JavaBeanWithStaticState) {
        List<NodeTuple> value = node.getValue();
        value.add(new NodeTuple(representData("color"),
                representData(JavaBeanWithStaticState.color)));
        value.add(new NodeTuple(representData("type"),
                representData(JavaBeanWithStaticState.getType())));
    }
    return node;
}
 
Example #28
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 #29
Source File: StackOverflowTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
@Override
protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
        Object propertyValue, Tag customTag) {
    if (javaBean instanceof Point && "location".equals(property.getName())) {
        return null;
    } else {
        return super
                .representJavaBeanProperty(javaBean, property, propertyValue, customTag);
    }
}
 
Example #30
Source File: AdvancedRepresenterTest.java    From waggle-dance with Apache License 2.0 5 votes vote down vote up
@Test
public void notNullProperty() throws Exception {
  bean.setProperty("value");
  Property property = new MethodProperty(getPropertyDescriptor("property"));
  NodeTuple nodeTuple = representer.representJavaBeanProperty(bean, property, bean.getProperty(), null);
  assertThat(nodeTuple, is(notNullValue()));
  assertThat(nodeTuple.getKeyNode(), is(instanceOf(ScalarNode.class)));
  assertThat(((ScalarNode) nodeTuple.getKeyNode()).getValue(), is("property"));
  assertThat(nodeTuple.getValueNode(), is(instanceOf(ScalarNode.class)));
  assertThat(((ScalarNode) nodeTuple.getValueNode()).getValue(), is("value"));
}