public class Data
Utilities for working with key/value data based on the Key annotation.
Static Fields
NULL_BIG_DECIMAL
public static final BigDecimal NULL_BIG_DECIMAL
The single instance of the magic null object for a BigDecimal.
Field Value | |
---|---|
Type | Description |
BigDecimal |
NULL_BIG_INTEGER
public static final BigInteger NULL_BIG_INTEGER
The single instance of the magic null object for a BigInteger.
Field Value | |
---|---|
Type | Description |
BigInteger |
NULL_BOOLEAN
public static final Boolean NULL_BOOLEAN
The single instance of the magic null object for a Boolean.
Field Value | |
---|---|
Type | Description |
Boolean |
NULL_BYTE
public static final Byte NULL_BYTE
The single instance of the magic null object for a Byte.
Field Value | |
---|---|
Type | Description |
Byte |
NULL_CHARACTER
public static final Character NULL_CHARACTER
The single instance of the magic null object for a Character.
Field Value | |
---|---|
Type | Description |
Character |
NULL_DATE_TIME
public static final DateTime NULL_DATE_TIME
The single instance of the magic null object for a DateTime.
Field Value | |
---|---|
Type | Description |
DateTime |
NULL_DOUBLE
public static final Double NULL_DOUBLE
The single instance of the magic null object for a Double.
Field Value | |
---|---|
Type | Description |
Double |
NULL_FLOAT
public static final Float NULL_FLOAT
The single instance of the magic null object for a Float.
Field Value | |
---|---|
Type | Description |
Float |
NULL_INTEGER
public static final Integer NULL_INTEGER
The single instance of the magic null object for a Integer.
Field Value | |
---|---|
Type | Description |
Integer |
NULL_LONG
public static final Long NULL_LONG
The single instance of the magic null object for a Long.
Field Value | |
---|---|
Type | Description |
Long |
NULL_SHORT
public static final Short NULL_SHORT
The single instance of the magic null object for a Short.
Field Value | |
---|---|
Type | Description |
Short |
NULL_STRING
public static final String NULL_STRING
The single instance of the magic null object for a String.
Field Value | |
---|---|
Type | Description |
String |
Static Methods
clone(T data)
public static T <T>clone(T data)
Returns a deep clone of the given key/value data, such that the result is a completely independent copy.
This should not be used directly in the implementation of Object.clone()
. Instead
use #deepCopy(Object, Object) for that purpose.
Final fields cannot be changed and therefore their value won't be copied.
Parameter | |
---|---|
Name | Description |
data |
T key/value data object or map to clone or |
Returns | |
---|---|
Type | Description |
T |
deep clone or |
nullOf(Class objClass)
public static T <T>nullOf(Class objClass)
Returns the single instance of the magic object that represents the "null" value for the given Java class (including array or enum).
Parameter | |
---|---|
Name | Description |
objClass |
Class<T> class of the object needed |
Returns | |
---|---|
Type | Description |
T |
magic object instance that represents the "null" value (not Java |
deepCopy(Object src, Object dest)
public static void deepCopy(Object src, Object dest)
Makes a deep copy of the given source object into the destination object that is assumed to be
constructed using Object.clone()
.
Example usage of this method in Object.clone()
:
@Override public MyObject clone() { try { @SuppressWarnings("unchecked") MyObject result = (MyObject) super.clone(); Data.deepCopy(this, result); return result; } catch (CloneNotSupportedException e) { throw new IllegalStateException(e); } }
Final fields cannot be changed and therefore their value won't be copied.
Parameters | |
---|---|
Name | Description |
src |
Object source object |
dest |
Object destination object of identical type as source object, and any contained arrays must be the same length |
isNull(Object object)
public static boolean isNull(Object object)
Returns whether the given object is the magic object that represents the null value of its class.
Parameter | |
---|---|
Name | Description |
object |
Object object or |
Returns | |
---|---|
Type | Description |
boolean |
whether it is the magic null value or |
isPrimitive(Type type)
public static boolean isPrimitive(Type type)
Returns whether the given type is one of the supported primitive classes like number and date/time, or is a wildcard of one.
A primitive class is any class for whom Class#isPrimitive() is true, as well as any classes of type: Character, String, Integer, Long, Short, Byte, Float, Double, BigInteger, BigDecimal, Boolean, and DateTime.
Parameter | |
---|---|
Name | Description |
type |
Type type or |
Returns | |
---|---|
Type | Description |
boolean |
whether it is a primitive |
isValueOfPrimitiveType(Object fieldValue)
public static boolean isValueOfPrimitiveType(Object fieldValue)
Returns whether to given value is null
or its class is primitive as defined by Data#isPrimitive(Type).
Parameter | |
---|---|
Name | Description |
fieldValue |
Object |
Returns | |
---|---|
Type | Description |
boolean |
mapOf(Object data)
public static Map,Object> mapOf(Object data)
Returns the map to use for the given data that is treated as a map from string key to some value.
If the input is any key value data, represented by an object or a map, or key/value map to use Returns a new collection instance for the given type. Creates a new collection instance specified for the first input collection class that
matches as follows: type or new collection instance Returns a new instance of a map based on the given field class. Creates a new map instance specified for the first input map class that matches as follows: field class Parses the given string value based on the given primitive type. Types are parsed as follows: Note that this may not be the right behavior for some use cases. primitive type or string value to parse or parsed object or Aggressively resolves the given type in such a way that the resolved type is not a wildcard
type or a type variable, returning context list, ordering from least specific to most specific type context, for
example container class and then its field type or resolved type (which may be class, parameterized type, or generic array type, but not
wildcard type or type variable) or Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Last updated 2025-06-12 UTC.null
, it returns an empty map. If the input is a map, it simply
returns the input. Otherwise, it will create a map view using reflection that is backed by the
object, so that any changes to the map will be reflected on the object. The map keys of that
map view are based on the Key annotation, and null is not a possible map value,
although the magic null instance is possible (see
Parameter
Name
Description
data
Object
null
Returns
Type
Description
Map<String,Object>
newCollectionInstance(Type type)
public static Collection newCollectionInstance(Type type)
null
or an array or assignable from ArrayList (like List or
Collection or Object): returns an ArrayList
Parameter
Name
Description
type
Type
null
for ArrayList.
Returns
Type
Description
Collection<Object>
newMapInstance(Class> mapClass)
public static Map
null
or assignable from ArrayMap (like Map or Object):
returns an ArrayMap
Parameter
Name
Description
mapClass
Class<?>
Returns
Type
Description
Map<String,Object>
parsePrimitiveValue(Type type, String stringValue)
public static Object parsePrimitiveValue(Type type, String stringValue)
null
or is assignable from String (like Object): no parsing
char
or Character: String.charAt(0) (requires
length to be exactly 1)
boolean
or Boolean: Boolean#valueOf(String)
byte
or Byte: Byte#valueOf(String)
short
or Short: Short#valueOf(String)
int
or Integer: Integer#valueOf(String)
long
or Long: Long#valueOf(String)
float
or Float: Float#valueOf(String)
double
or Double: Double#valueOf(String)
Parameters
Name
Description
type
Type
null
to parse as a string
stringValue
String
null
for null
result
Returns
Type
Description
Object
null
for null
inputresolveWildcardTypeOrTypeVariable(List
public static Type resolveWildcardTypeOrTypeVariable(List
Object.class
if the type variable cannot be
resolved.
Parameters
Name
Description
context
List<Type>
type
Type
null
for null
result
Returns
Type
Description
Type
null
for null
inputConstructors
Data()
public Data()