Package generic.json

Class Json

java.lang.Object
org.apache.commons.lang3.builder.ToStringStyle
generic.json.Json
All Implemented Interfaces:
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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A ToStringStyle inspired by ToStringStyle.JSON_STYLE that places object fields all on one line, with Json style formatting.
    static class 
    A ToStringStyle inspired by ToStringStyle.JSON_STYLE that places object fields on newlines for more readability
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     

    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
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Creates a Json string representation of the given object and all of its fields.
    static String
    toString(Object o, String... includFields)
    Creates a Json string representation of the given object and the given fields
    static String
    toStringExclude(Object o, String... excludedFields)
    Creates a Json string representation of the given object and all of its fields except for those in the given exclusion list
    static String
    Creates a Json string representation of the given object and all of its fields.

    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, 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
  • Field Details

  • Constructor Details

    • Json

      public Json()
  • Method Details

    • toString

      public static String toString(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).

      The returned string is formatted for pretty printing using whitespace, such as tabs and newlines.

      Parameters:
      o - the object
      Returns:
      the string
    • toStringFlat

      public static String toStringFlat(Object o)
      Creates a Json string representation of the given object and all of its fields.

      The returned string is formatted without newlines for better use in logging.

      Parameters:
      o - the object
      Returns:
      the string
    • toString

      public static String toString(Object o, 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 String toStringExclude(Object o, 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