Package org.yaml.snakeyaml.nodes

Examples of org.yaml.snakeyaml.nodes.Node


  // Code borrowed from snakeyaml
  // (http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyaml/issues/issue60/SkipBeanTest.java)
  @Override
  protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
    NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
    Node valueNode = tuple.getValueNode();
    if (valueNode instanceof CollectionNode) {
      // Removed null check
      if (Tag.SEQ.equals(valueNode.getTag())) {
        SequenceNode seq = (SequenceNode) valueNode;
        if (seq.getValue().isEmpty()) { return null; // skip empty lists
        }
      }
      if (Tag.MAP.equals(valueNode.getTag())) {
        MappingNode seq = (MappingNode) valueNode;
        if (seq.getValue().isEmpty()) { return null; // skip empty maps
        }
      }
    }
View Full Code Here


        assertNull("The tag should not be specified: " + tag, tag);
    }

    public void testDump() {
        Yaml yaml = new Yaml();
        Node intNode = yaml.represent(7);
        assertEquals("tag:yaml.org,2002:int", intNode.getTag().toString());
        // System.out.println(intNode);
        List<Event> intEvents = yaml.serialize(intNode);
        String tag = ((ScalarEvent) intEvents.get(2)).getTag();
        assertEquals("Without the tag emitter would not know how to emit '7'",
                "tag:yaml.org,2002:int", tag);
        //
        Node strNode = yaml.represent("7");
        assertEquals("tag:yaml.org,2002:str", strNode.getTag().toString());
        // System.out.println(strNode);
    }
View Full Code Here

    protected Object objectToRepresent;
    private PropertyUtils propertyUtils;
    private boolean explicitPropertyUtils = false;

    public Node represent(Object data) {
        Node node = representData(data);
        representedObjects.clear();
        objectToRepresent = null;
        return node;
    }
View Full Code Here

    protected final Node representData(Object data) {
        objectToRepresent = data;
        // check for identity
        if (representedObjects.containsKey(objectToRepresent)) {
            Node node = representedObjects.get(objectToRepresent);
            return node;
        }
        // }
        // check for null first
        if (data == null) {
            Node node = nullRepresenter.representData(null);
            return node;
        }
        // check the same class
        Node node;
        Class<?> clazz = data.getClass();
        if (representers.containsKey(clazz)) {
            Represent representer = representers.get(clazz);
            node = representer.representData(data);
        } else {
View Full Code Here

    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;
    }
View Full Code Here

        List<Node> value = new ArrayList<Node>(size);
        SequenceNode node = new SequenceNode(tag, value, flowStyle);
        representedObjects.put(objectToRepresent, node);
        boolean bestStyle = true;
        for (Object item : sequence) {
            Node nodeItem = representData(item);
            if (!((nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null))) {
                bestStyle = false;
            }
            value.add(nodeItem);
        }
View Full Code Here

        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<? extends Object, Object> 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;
View Full Code Here

            longEscURI = longEscURI + longEscURI;
        }
        assertEquals(1024 * 3, longEscURI.length());
        String yaml = "!" + longEscURI + " www";

        Node node = loader.compose(new StringReader(yaml));
        ScalarNode scalar = (ScalarNode) node;
        String etalon = "!";
        for (int i = 0; i < 1024; i++) {
            etalon += "A";
        }
View Full Code Here

                SequenceNode seq2 = (SequenceNode) node2;
                assertEquals(seq1.getTag(), seq2.getTag());
                assertEquals(seq1.getValue().size(), seq2.getValue().size());
                Iterator<Node> iter2 = seq2.getValue().iterator();
                for (Node child1 : seq1.getValue()) {
                    Node child2 = iter2.next();
                    compareNodes(child1, child2);
                }
            } else {
                MappingNode seq1 = (MappingNode) node1;
                MappingNode seq2 = (MappingNode) node2;
                assertEquals(seq1.getTag(), seq2.getTag());
                assertEquals(seq1.getValue().size(), seq2.getValue().size());
                Iterator<NodeTuple> iter2 = seq2.getValue().iterator();
                for (NodeTuple child1 : seq1.getValue()) {
                    NodeTuple child2 = iter2.next();
                    compareNodes(child1.getKeyNode(), child2.getKeyNode());
                    compareNodes(child1.getValueNode(), child2.getValueNode());
                }
            }
        }
    }
View Full Code Here

        list.add(map);
        Yaml yaml = new Yaml();
        String etalon = yaml.dump(list);
        // System.out.println(etalon);
        //
        Node node = yaml.represent(list);
        // System.out.println(node);
        assertEquals(
                "Representation tree from an object and from its YAML document must be the same.",
                yaml.compose(new StringReader(etalon)).toString(), node.toString());
        //
        List<Event> events = yaml.serialize(node);
        int i = 0;
        for (Event etalonEvent : yaml.parse(new StringReader(etalon))) {
            Event ev1 = events.get(i++);
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.nodes.Node

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.