Package dev.morphia.mapping.codec.pojo
Class FieldModel
- java.lang.Object
-
- dev.morphia.mapping.codec.pojo.FieldModel
-
public final class FieldModel extends Object
Represents a field on a class and stores various metadata such as generic parameters.- Since:
- 2.0
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FieldModelBuilder
builder()
Create a newFieldModelBuilder
boolean
equals(Object o)
org.bson.codecs.pojo.PropertyAccessor<? super Object>
getAccessor()
<A extends Annotation>
AgetAnnotation(Class<A> type)
Find an annotation of a specific type or null if not found.org.bson.codecs.Codec<? super Object>
getCachedCodec()
org.bson.codecs.Codec<?>
getCodec()
Object
getDocumentValue(org.bson.Document document)
EntityModel
getEntityModel()
Field
getField()
String
getFullName()
List<String>
getLoadNames()
String
getMappedName()
String
getName()
Class<?>
getNormalizedType()
Gets the parameterized type of a List or the key type of a Map, e.g.Class<?>
getSpecializedType()
If the java field is a list/array/map then the sub-type T is returned (ex.Class<?>
getType()
TypeData<?>
getTypeData()
Object
getValue(Object instance)
Gets the value of the field mapped on the instance given.boolean
hasAnnotation(Class<? extends Annotation> type)
Indicates whether the annotation is present in the mapping (does not check the java field annotations, just the ones discovered)int
hashCode()
boolean
isArray()
boolean
isMap()
boolean
isMultipleValues()
boolean
isReference()
boolean
isScalarValue()
boolean
isSet()
boolean
isTransient()
static Class<?>
normalize(TypeData<?> toNormalize)
Gets the parameterized type of a TypeDatavoid
setValue(Object instance, Object value)
Sets the value for the java fieldboolean
shouldSerialize(Object value)
Checks a value against the configured rules for serializationString
toString()
-
-
-
Method Detail
-
builder
public static FieldModelBuilder builder()
Create a newFieldModelBuilder
- Returns:
- the builder
-
normalize
public static Class<?> normalize(TypeData<?> toNormalize)
Gets the parameterized type of a TypeData- Parameters:
toNormalize
- the type to normalize- Returns:
- the unwrapped type
Developer note.This is an internal item. Its function and presence are subject to change without warning. Its use is highly discouraged.
-
getAccessor
public org.bson.codecs.pojo.PropertyAccessor<? super Object> getAccessor()
- Returns:
- the accessor to use when accessing this field
-
getAnnotation
public <A extends Annotation> A getAnnotation(Class<A> type)
Find an annotation of a specific type or null if not found.- Type Parameters:
A
- the class type- Parameters:
type
- the annotation type to find- Returns:
- the annotation instance or null
-
getCachedCodec
public org.bson.codecs.Codec<? super Object> getCachedCodec()
- Returns:
- the cached codec
-
getCodec
public org.bson.codecs.Codec<?> getCodec()
- Returns:
- the custom codec to use if set or null
-
getDocumentValue
public Object getDocumentValue(org.bson.Document document)
- Parameters:
document
- the Document get the value from- Returns:
- the value from first mapping of this field
-
getEntityModel
public EntityModel getEntityModel()
- Returns:
- the entity model owner of this field
- Since:
- 2.1
-
getField
public Field getField()
- Returns:
- the field
-
getFullName
public String getFullName()
- Returns:
- the full name of the class plus java field name
-
getLoadNames
public List<String> getLoadNames()
- Returns:
- the name of the field's (key)name for mongodb, in order of loading.
-
getMappedName
public String getMappedName()
- Returns:
- the mapped name for the model
-
getName
public String getName()
- Returns:
- the field name for the model
-
getNormalizedType
public Class<?> getNormalizedType()
Gets the parameterized type of a List or the key type of a Map, e.g.- Returns:
- the unwrapped type
-
getSpecializedType
public Class<?> getSpecializedType()
If the java field is a list/array/map then the sub-type T is returned (ex. List<T>, T[], Map<?,T>)- Returns:
- the parameterized type of the field
-
getType
public Class<?> getType()
- Returns:
- the type of this field
-
getTypeData
public TypeData<?> getTypeData()
- Returns:
- the type data for the field
-
getValue
public Object getValue(Object instance)
Gets the value of the field mapped on the instance given.- Parameters:
instance
- the instance to use- Returns:
- the value stored in the java field
-
hasAnnotation
public boolean hasAnnotation(Class<? extends Annotation> type)
Indicates whether the annotation is present in the mapping (does not check the java field annotations, just the ones discovered)- Parameters:
type
- the annotation to search for- Returns:
- true if the annotation was found
-
isArray
public boolean isArray()
- Returns:
- true if the MappedField is an array
-
isMap
public boolean isMap()
- Returns:
- true if the MappedField is a Map
-
isMultipleValues
public boolean isMultipleValues()
- Returns:
- true if this field is a container type such as a List, Map, Set, or array
-
isReference
public boolean isReference()
-
isScalarValue
public boolean isScalarValue()
- Returns:
- true if this field is not a container type such as a List, Map, Set, or array
-
isSet
public boolean isSet()
- Returns:
- true if the MappedField is a Set
-
isTransient
public boolean isTransient()
- Returns:
- true if this field is marked as transient
-
setValue
public void setValue(Object instance, Object value)
Sets the value for the java field- Parameters:
instance
- the instance to updatevalue
- the value to set
-
shouldSerialize
public boolean shouldSerialize(Object value)
Checks a value against the configured rules for serialization- Parameters:
value
- the value to check- Returns:
- true if the given value should be serialized
-
-