Package generic.json

Class Json

  • All Implemented Interfaces:
    java.io.Serializable

    public class Json
    extends org.apache.commons.lang3.builder.ToStringStyle
    A utility class to format strings in JSON format. This is useful for easily generating toString() representations of objects.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Json.JsonWithNewlinesToStringStyle
      A ToStringStyle inspired by ToStringStyle.JSON_STYLE that places object fields on newlines for more readability
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Json.JsonWithNewlinesToStringStyle WITH_NEWLINES  
      • Fields inherited from class org.apache.commons.lang3.builder.ToStringStyle

        DEFAULT_STYLE, JSON_STYLE, MULTI_LINE_STYLE, NO_CLASS_NAME_STYLE, NO_FIELD_NAMES_STYLE, SHORT_PREFIX_STYLE, SIMPLE_STYLE
    • Constructor Summary

      Constructors 
      Constructor Description
      Json()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String toString​(java.lang.Object o)
      Creates a Json string representation of the given object and all of its fields.
      static java.lang.String toString​(java.lang.Object o, java.lang.String... includFields)
      Creates a Json string representation of the given object and the given fields
      static java.lang.String toStringExclude​(java.lang.Object o, java.lang.String... excludedFields)
      Creates a Json string representation of the given object and all of its fields except for those in the given exclusion list
      • Methods inherited from class org.apache.commons.lang3.builder.ToStringStyle

        append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, appendClassName, appendContentEnd, appendContentStart, appendCyclicObject, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendDetail, appendEnd, appendFieldEnd, appendFieldSeparator, appendFieldStart, appendIdentityHashCode, appendInternal, appendNullText, appendStart, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummary, appendSummarySize, appendSuper, appendToString, getArrayEnd, getArraySeparator, getArrayStart, getContentEnd, getContentStart, getFieldNameValueSeparator, getFieldSeparator, getNullText, getShortClassName, getSizeEndText, getSizeStartText, getSummaryObjectEndText, getSummaryObjectStartText, isArrayContentDetail, isDefaultFullDetail, isFieldSeparatorAtEnd, isFieldSeparatorAtStart, isFullDetail, isUseClassName, isUseFieldNames, isUseIdentityHashCode, isUseShortClassName, reflectionAppendArrayDetail, removeLastFieldSeparator, setArrayContentDetail, setArrayEnd, setArraySeparator, setArrayStart, setContentEnd, setContentStart, setDefaultFullDetail, setFieldNameValueSeparator, setFieldSeparator, setFieldSeparatorAtEnd, setFieldSeparatorAtStart, setNullText, setSizeEndText, setSizeStartText, setSummaryObjectEndText, setSummaryObjectStartText, setUseClassName, setUseFieldNames, setUseIdentityHashCode, setUseShortClassName
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Json

        public Json()
    • Method Detail

      • toString

        public static java.lang.String toString​(java.lang.Object o)
        Creates a Json string representation of the given object and all of its fields. To exclude some fields, call toStringExclude(Object, String...). To only include particular fields, call ToStringStyle.appendToString(StringBuffer, String).
        Parameters:
        o - the object
        Returns:
        the string
      • toString

        public static java.lang.String toString​(java.lang.Object o,
                                                java.lang.String... includFields)
        Creates a Json string representation of the given object and the given fields
        Parameters:
        o - the object
        includFields - the fields to include
        Returns:
        the string
      • toStringExclude

        public static java.lang.String toStringExclude​(java.lang.Object o,
                                                       java.lang.String... excludedFields)
        Creates a Json string representation of the given object and all of its fields except for those in the given exclusion list
        Parameters:
        o - the object
        excludedFields - the excluded field names
        Returns:
        the string