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
Modifier and TypeClassDescriptionstatic class
AToStringStyle
inspired byToStringStyle.JSON_STYLE
that places object fields all on one line, with Json style formatting.static class
AToStringStyle
inspired byToStringStyle.JSON_STYLE
that places object fields on newlines for more readability -
Field Summary
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
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
Creates a Json string representation of the given object and all of its fields.static String
Creates a Json string representation of the given object and the given fieldsstatic 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 liststatic 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
-
Field Details
-
WITH_NEWLINES
-
-
Constructor Details
-
Json
public Json()
-
-
Method Details
-
toString
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)
.The returned string is formatted for pretty printing using whitespace, such as tabs and newlines.
- Parameters:
o
- the object- Returns:
- the string
-
toStringFlat
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
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
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
-