Package generic.json
Class Json
- java.lang.Object
-
- org.apache.commons.lang3.builder.ToStringStyle
-
- generic.json.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 generatingtoString()
representations of objects.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Json.JsonWithNewlinesToStringStyle
AToStringStyle
inspired byToStringStyle.JSON_STYLE
that places object fields on newlines for more readability
-
Field Summary
Fields Modifier and Type Field Description static Json.JsonWithNewlinesToStringStyle
WITH_NEWLINES
-
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 fieldsstatic 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
-
-
-
-
Field Detail
-
WITH_NEWLINES
public static final Json.JsonWithNewlinesToStringStyle WITH_NEWLINES
-
-
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, calltoStringExclude(Object, String...)
. To only include particular fields, callToStringStyle.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 objectincludFields
- 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 objectexcludedFields
- the excluded field names- Returns:
- the string
-
-