Class ToStringStyle.JsonToStringStyle

  • All Implemented Interfaces:
    java.io.Serializable
    Enclosing class:
    ToStringStyle

    private static final class ToStringStyle.JsonToStringStyle
    extends ToStringStyle

    ToStringStyle that outputs with JSON format.

    This is an inner class rather than using StandardToStringStyle to ensure its immutability.

    Since:
    3.4
    See Also:
    json.org
    • Constructor Detail

      • JsonToStringStyle

        JsonToStringStyle()

        Constructor.

        Use the static constant rather than instantiating.

    • Method Detail

      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           java.lang.Object[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString an Object array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           long[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString a long array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           int[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString an int array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           short[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString a short array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           byte[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString a byte array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           char[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString a char array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           double[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString a double array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           float[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString a float array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           boolean[] array,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString a boolean array.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        array - the array to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • append

        public void append​(java.lang.StringBuffer buffer,
                           java.lang.String fieldName,
                           java.lang.Object value,
                           java.lang.Boolean fullDetail)
        Description copied from class: ToStringStyle

        Append to the toString an Object value, printing the full toString of the Object passed in.

        Overrides:
        append in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
        value - the value to add to the toString
        fullDetail - true for detail, false for summary info, null for style decides
      • appendDetail

        protected void appendDetail​(java.lang.StringBuffer buffer,
                                    java.lang.String fieldName,
                                    char value)
        Description copied from class: ToStringStyle

        Append to the toString a char value.

        Overrides:
        appendDetail in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name, typically not used as already appended
        value - the value to add to the toString
      • appendDetail

        protected void appendDetail​(java.lang.StringBuffer buffer,
                                    java.lang.String fieldName,
                                    java.lang.Object value)
        Description copied from class: ToStringStyle

        Append to the toString an Object value, printing the full detail of the Object.

        Overrides:
        appendDetail in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name, typically not used as already appended
        value - the value to add to the toString, not null
      • appendDetail

        protected void appendDetail​(java.lang.StringBuffer buffer,
                                    java.lang.String fieldName,
                                    java.util.Collection<?> coll)
        Description copied from class: ToStringStyle

        Append to the toString a Collection.

        Overrides:
        appendDetail in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name, typically not used as already appended
        coll - the Collection to add to the toString, not null
      • appendDetail

        protected void appendDetail​(java.lang.StringBuffer buffer,
                                    java.lang.String fieldName,
                                    java.util.Map<?,​?> map)
        Description copied from class: ToStringStyle

        Append to the toString a Map.

        Overrides:
        appendDetail in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name, typically not used as already appended
        map - the Map to add to the toString, not null
      • isJsonArray

        private boolean isJsonArray​(java.lang.String valueAsString)
      • isJsonObject

        private boolean isJsonObject​(java.lang.String valueAsString)
      • appendValueAsString

        private void appendValueAsString​(java.lang.StringBuffer buffer,
                                         java.lang.String value)
        Appends the given String enclosed in double-quotes to the given StringBuffer.
        Parameters:
        buffer - the StringBuffer to append the value to.
        value - the value to append.
      • appendFieldStart

        protected void appendFieldStart​(java.lang.StringBuffer buffer,
                                        java.lang.String fieldName)
        Description copied from class: ToStringStyle

        Append to the toString the field start.

        Overrides:
        appendFieldStart in class ToStringStyle
        Parameters:
        buffer - the StringBuffer to populate
        fieldName - the field name
      • readResolve

        private java.lang.Object readResolve()

        Ensure Singleton after serialization.

        Returns:
        the singleton