Class BaseRepresenter

  • Direct Known Subclasses:
    StandardRepresenter

    public abstract class BaseRepresenter
    extends java.lang.Object
    Represent basic YAML structures: scalar, sequence, mapping
    • Field Detail

      • representers

        protected final java.util.Map<java.lang.Class<?>,​RepresentToNode> representers
        Keep representers which must match the class exactly
      • parentClassRepresenters

        protected final java.util.Map<java.lang.Class<?>,​RepresentToNode> parentClassRepresenters
        Keep representers which match a parent of the class to be represented
      • representedObjects

        protected final java.util.Map<java.lang.Object,​Node> representedObjects
        Keep references of already represented instances. The order is important (map can be also a sequence of key-values)
      • nullRepresenter

        protected RepresentToNode nullRepresenter
        in Java 'null' is not a type. So we have to keep the null representer separately
      • defaultScalarStyle

        protected ScalarStyle defaultScalarStyle
        scalar style
      • defaultFlowStyle

        protected FlowStyle defaultFlowStyle
        flow style for collections
      • objectToRepresent

        protected java.lang.Object objectToRepresent
        the current object to be converted to Node
    • Constructor Detail

      • BaseRepresenter

        public BaseRepresenter()
    • Method Detail

      • represent

        public Node represent​(java.lang.Object data)
        Represent the provided Java instance to a Node
        Parameters:
        data - - Java instance to be represented
        Returns:
        The Node to be serialized
      • findRepresenterFor

        protected java.util.Optional<RepresentToNode> findRepresenterFor​(java.lang.Object data)
        Find the representer which is suitable to represent the internal structure of the provided instance to a Node
        Parameters:
        data - - the data to be serialized
        Returns:
        RepresentToNode to call to create a Node
      • representData

        protected final Node representData​(java.lang.Object data)
        Find the representer and use it to create the Node from instance
        Parameters:
        data - - the source
        Returns:
        Node for the provided source
      • representScalar

        protected Node representScalar​(Tag tag,
                                       java.lang.String value,
                                       ScalarStyle style)
        Create Scalar Node from string
        Parameters:
        tag - - the tag in Node
        value - - the source
        style - - the style
        Returns:
        Node for string
      • representScalar

        protected Node representScalar​(Tag tag,
                                       java.lang.String value)
        Create Node for string using PLAIN scalar style if possible
        Parameters:
        tag - - the tag for Node
        value - - the surce
        Returns:
        Node for string
      • representSequence

        protected Node representSequence​(Tag tag,
                                         java.lang.Iterable<?> sequence,
                                         FlowStyle flowStyle)
        Create Node
        Parameters:
        tag - - tag to use in Node
        sequence - - the source
        flowStyle - - the flow style
        Returns:
        the Node from the source iterable
      • representMappingEntry

        protected NodeTuple representMappingEntry​(java.util.Map.Entry<?,​?> entry)
        Create a tuple for one key pair
        Parameters:
        entry - - Map entry
        Returns:
        the tuple where both key and value are converted to Node
      • representMapping

        protected Node representMapping​(Tag tag,
                                        java.util.Map<?,​?> mapping,
                                        FlowStyle flowStyle)
        Create Node for the provided Map
        Parameters:
        tag - - the tag for Node
        mapping - - the source
        flowStyle - - the style of Node
        Returns:
        Node for the source Map