Java Code Examples for org.yaml.snakeyaml.introspector.Property#get()

The following examples show how to use org.yaml.snakeyaml.introspector.Property#get() . 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: 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 2
Source File: Representer.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Tag logic:
 * - explicit root tag is set in serializer
 * - if there is a predefined class tag it is used
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 *
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag("!" + javaBean.getClass().getSimpleName());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag, value, FlowStyle.AUTO);
    representedObjects.put(javaBean, node);
    DumperOptions.FlowStyle bestStyle = FlowStyle.FLOW;
    for (Property property : properties) {
        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;
        }
        if (!((ScalarNode) tuple.getKeyNode()).isPlain()) {
            bestStyle = FlowStyle.BLOCK;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).isPlain())) {
            bestStyle = FlowStyle.BLOCK;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle);
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
 
Example 3
Source File: Representer.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tag logic:<br/>
 * - explicit root tag is set in serializer <br/>
 * - if there is a predefined class tag it is used<br/>
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 * 
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag, value, null);
    representedObjects.put(javaBean, node);
    boolean bestStyle = true;
    for (Property property : properties) {
        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;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!((nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null))) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
 
Example 4
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 5
Source File: Representer.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
/**
 * Tag logic:<br>
 * - explicit root tag is set in serializer <br>
 * - if there is a predefined class tag it is used<br>
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 *
 * @param properties
 *            JavaBean getters
 * @param javaBean
 *            instance for Node
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
    List<NodeTuple> value = new ArrayList<NodeTuple>(properties.size());
    Tag tag;
    Tag customTag = classTags.get(javaBean.getClass());
    tag = customTag != null ? customTag : new Tag(javaBean.getClass());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag, value, null);
    representedObjects.put(javaBean, node);
    boolean bestStyle = true;
    for (Property property : properties) {
        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;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null) {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (!(nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null)) {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (defaultFlowStyle != FlowStyle.AUTO) {
        node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
    } else {
        node.setFlowStyle(bestStyle);
    }
    return node;
}
 
Example 6
Source File: Representer.java    From Diorite with MIT License 4 votes vote down vote up
/**
 * Tag logic:<br>
 * - explicit root tag is set in serializer <br>
 * - if there is a predefined class tag it is used<br>
 * - a global tag with class name is always used as tag. The JavaBean parent
 * of the specified JavaBean may set another tag (tag:yaml.org,2002:map)
 * when the property class is the same as runtime class
 *
 * @param properties
 *         JavaBean getters
 * @param javaBean
 *         instance for Node
 *
 * @return Node to get serialized
 */
protected MappingNode representJavaBean(Set<Property> properties, Object javaBean)
{
    List<NodeTuple> value = new ArrayList<>(properties.size());
    Tag tag;
    Tag customTag = this.classTags.get(javaBean.getClass());
    tag = (customTag != null) ? customTag : new Tag(javaBean.getClass());
    // flow style will be chosen by BaseRepresenter
    MappingNode node = new MappingNode(tag, value, null);
    this.representedObjects.put(javaBean, node);
    boolean bestStyle = true;
    for (Property property : properties)
    {
        Object memberValue = property.get(javaBean);
        Tag customPropertyTag = (memberValue == null) ? null : this.classTags.get(memberValue.getClass());
        NodeTuple tuple = this.representJavaBeanProperty(javaBean, property, memberValue, customPropertyTag);
        if (tuple == null)
        {
            continue;
        }
        if (((ScalarNode) tuple.getKeyNode()).getStyle() != null)
        {
            bestStyle = false;
        }
        Node nodeValue = tuple.getValueNode();
        if (! ((nodeValue instanceof ScalarNode) && (((ScalarNode) nodeValue).getStyle() == null)))
        {
            bestStyle = false;
        }
        value.add(tuple);
    }
    if (this.defaultFlowStyle != FlowStyle.AUTO)
    {
        node.setFlowStyle(this.defaultFlowStyle.getStyleBoolean());
    }
    else
    {
        node.setFlowStyle(bestStyle);
    }
    return node;
}