java.lang.Object
com.google.gson.FieldAttributes
A data object that stores attributes of a field.
This class is immutable; therefore, it can be safely shared across threads.
- Since:
- 1.4
- Author:
- Inderjeet Singh, Joel Leitch
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription<T extends Annotation>
TgetAnnotation
(Class<T> annotation) Return theT
annotation object from this field if it exist; otherwise returnsnull
.Return the annotations that are present on this field.Class<?>
Returns theClass
object that was declared for this field.For example, assume the following class definition:Class<?>
getName()
boolean
hasModifier
(int modifier) Returnstrue
if the field is defined with themodifier
.toString()
-
Constructor Details
-
FieldAttributes
Constructs a Field Attributes object from thef
.- Parameters:
f
- the field to pull attributes from
-
-
Method Details
-
getDeclaringClass
- Returns:
- the declaring class that contains this field
-
getName
- Returns:
- the name of the field
-
getDeclaredType
For example, assume the following class definition:
public class Foo { private String bar; private List<String> red; } Type listParameterizedType = new TypeToken<List<String>>() {}.getType();
This method would return
String.class
for thebar
field andlistParameterizedType
for thered
field.- Returns:
- the specific type declared for this field
-
getDeclaredClass
Returns theClass
object that was declared for this field.For example, assume the following class definition:
public class Foo { private String bar; private List<String> red; }
This method would return
String.class
for thebar
field andList.class
for thered
field.- Returns:
- the specific class object that was declared for the field
-
getAnnotation
Return theT
annotation object from this field if it exist; otherwise returnsnull
.- Parameters:
annotation
- the class of the annotation that will be retrieved- Returns:
- the annotation instance if it is bound to the field; otherwise
null
-
getAnnotations
Return the annotations that are present on this field.- Returns:
- an array of all the annotations set on the field
- Since:
- 1.4
-
hasModifier
public boolean hasModifier(int modifier) Returnstrue
if the field is defined with themodifier
.This method is meant to be called as:
boolean hasPublicModifier = fieldAttribute.hasModifier(java.lang.reflect.Modifier.PUBLIC);
- See Also:
-
toString
-