Package org.yaml.snakeyaml.nodes

Examples of org.yaml.snakeyaml.nodes.MappingNode


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


        if (mapping.isEmpty()) {
            return null;
        }

        List<NodeTuple> value = new LinkedList<NodeTuple>();
        MappingNode node = new MappingNode(tag, value, flowStyle);
        representedObjects.put(objectToRepresent, node);
        boolean bestStyle = true;
        for (Object itemKey : mapping.keySet()) {
            Object itemValue = mapping.get(itemKey);
            Node nodeKey = representData(itemKey);
            Node nodeValue = representData(itemValue);

            // If the node value is null (see above) then skip
            if (nodeValue == null) {
                continue;
            }
           
            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 != null) {
                node.setFlowStyle(defaultFlowStyle);
            } else {
                node.setFlowStyle(bestStyle);
            }
        }
        return node;
    }
View Full Code Here

        List<NodeTuple> value = new LinkedList<NodeTuple>();
        String tag;
        String customTag = Tags.MAP;
        tag = customTag != null ? customTag : Tags.getGlobalTagForClass( javaBean.getClass() );
        // flow style will be chosen by BaseRepresenter
        MappingNode node = new MappingNode( tag, value, null );
        representedObjects.put( objectToRepresent, node );
        boolean bestStyle = true;
        for ( Property property : properties )
        {
            ScalarNode nodeKey = (ScalarNode) representData( property.getName() );
            Object memberValue = property.get( javaBean );
            boolean hasAlias = false;
            if ( representedObjects.containsKey( memberValue ) )
            {
                // the first occurrence of the node must keep the tag
                hasAlias = true;
            }
            Node nodeValue = representData( memberValue );

            // TODO: The impl seems not to allow to skip certain values
            if ( nodeValue == null )
            {
                continue;
            }

            // if possible try to avoid a global tag with a class name
            if ( nodeValue instanceof MappingNode && !hasAlias )
            {
                // the node is a map, set or JavaBean
                if ( !Map.class.isAssignableFrom( memberValue.getClass() ) )
                {
                    // the node is set or JavaBean
                    if ( property.getType() == memberValue.getClass() )
                    {
                        // we do not need global tag because the property
                        // Class is the same as the runtime class
                        nodeValue.setTag( Tags.MAP );
                    }
                }
            }
            else if ( memberValue != null && Enum.class.isAssignableFrom( memberValue.getClass() ) )
            {
                nodeValue.setTag( Tags.STR );
            }
            if ( nodeKey.getStyle() != null )
            {
                bestStyle = false;
            }
            if ( !( ( nodeValue instanceof ScalarNode && ( (ScalarNode) nodeValue ).getStyle() == null ) ) )
            {
                bestStyle = false;
            }
            value.add( new NodeTuple( nodeKey, nodeValue ) );
        }
        if ( defaultFlowStyle != null )
        {
            node.setFlowStyle( defaultFlowStyle );
        }
        else
        {
            node.setFlowStyle( bestStyle );
        }
        return node;
    }
View Full Code Here

TOP

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

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.