Class JSONUtils
java.lang.Object
nonapi.io.github.classgraph.json.JSONUtils
Utils for Java serialization and deserialization.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final StringJSON object key name for objects that are linked to from more than one object.(package private) static final StringJSON object reference id prefix.(package private) static final StringJSON object reference id suffix.private static final String[]Lookup table for fast indenting.private static Methodprivate static final String[]JSON character-to-string escaping replacements -- see http://www.json.org/ under "string".private static Methodprivate static Method -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringescapeJSONString(String unsafeStr) Escape a string to be surrounded in double quotes in JSON.(package private) static voidescapeJSONString(String unsafeStr, StringBuilder buf) Escape a string to be surrounded in double quotes in JSON.(package private) static booleanfieldIsSerializable(Field field, boolean onlySerializePublicFields, ReflectionUtils reflectionUtils) Check if a field is serializable.(package private) static ObjectgetFieldValue(Object containingObj, Field field) Get a field value, appropriately handling primitive-typed fields.(package private) static Class<?> getRawType(Type type) Get the raw type from a Type.(package private) static voidindent(int depth, int indentWidth, StringBuilder buf) Indent (depth * indentWidth) spaces.private static boolean(package private) static booleanisBasicValueType(Class<?> cls) Return true for classes that can be equal to a basic value type (types that can be converted directly to and from string representation).(package private) static booleanisBasicValueType(Object obj) Return true for objects that can be converted directly to and from string representation.(package private) static booleanisBasicValueType(Type type) Return true for types that can be converted directly to and from string representation.(package private) static booleanReturn true for objects that are collections or arrays (i.e.static booleanmakeAccessible(AccessibleObject obj, ReflectionUtils reflectionUtils) private static boolean
-
Field Details
-
isAccessibleMethod
-
setAccessibleMethod
-
trySetAccessibleMethod
-
ID_KEY
-
ID_PREFIX
-
ID_SUFFIX
-
JSON_CHAR_REPLACEMENTS
JSON character-to-string escaping replacements -- see http://www.json.org/ under "string". -
INDENT_LEVELS
Lookup table for fast indenting.
-
-
Constructor Details
-
JSONUtils
private JSONUtils()Constructor.
-
-
Method Details
-
isAccessible
-
tryMakeAccessible
-
makeAccessible
-
escapeJSONString
Escape a string to be surrounded in double quotes in JSON.- Parameters:
unsafeStr- the unsafe strbuf- the buf
-
escapeJSONString
-
indent
Indent (depth * indentWidth) spaces.- Parameters:
depth- the depthindentWidth- the indent widthbuf- the buf
-
getFieldValue
static Object getFieldValue(Object containingObj, Field field) throws IllegalArgumentException, IllegalAccessException Get a field value, appropriately handling primitive-typed fields.- Parameters:
containingObj- the containing objectfield- the field- Returns:
- the field value
- Throws:
IllegalArgumentException- if the specified object is not an instance of the class or interface declaring the underlying fieldIllegalAccessException- if the field cannot be read
-
isBasicValueType
Return true for classes that can be equal to a basic value type (types that can be converted directly to and from string representation).- Parameters:
cls- the class- Returns:
- true, if the class is a basic value type
-
isBasicValueType
Return true for types that can be converted directly to and from string representation.- Parameters:
type- the type- Returns:
- true, if the type is a basic value type
-
isBasicValueType
Return true for objects that can be converted directly to and from string representation.- Parameters:
obj- the object- Returns:
- true, if the object is null or of basic value type
-
isCollectionOrArray
Return true for objects that are collections or arrays (i.e. objects that are convertible to a JSON array).- Parameters:
obj- the object- Returns:
- true, if the object is a collection or array
-
getRawType
Get the raw type from a Type.- Parameters:
type- the type- Returns:
- the raw type
- Throws:
IllegalArgumentException- if passed a TypeVariable or anything other than aClass<?>reference orParameterizedType.
-
fieldIsSerializable
static boolean fieldIsSerializable(Field field, boolean onlySerializePublicFields, ReflectionUtils reflectionUtils) Check if a field is serializable. Don't serialize transient, final, synthetic, or inaccessible fields.N.B. Tries to set field to accessible, which will require an "opens" declarations from modules that want to allow this introspection.
- Parameters:
field- the fieldonlySerializePublicFields- if true, only serialize public fields- Returns:
- true if the field is serializable
-