public class FieldMapping extends Object
Parsed
in a record.Constructor and Description |
---|
FieldMapping(Class<?> beanClass,
AnnotatedElement target,
PropertyWrapper property,
HeaderTransformer transformer,
NormalizedString[] headers)
Creates the mapping and identifies how it is mapped (by name or by index)
|
Modifier and Type | Method and Description |
---|---|
boolean |
canWrite(Object instance)
Queries whether this field mapping can be applied over a given object instance.
|
boolean |
equals(Object o) |
NormalizedString |
getFieldName()
Returns the column name against which this field is mapped.
|
Class<?> |
getFieldParent()
Returns the parent class that contains the mapped field.
|
Class<?> |
getFieldType()
Returns the type of the mapped field
|
int |
getIndex()
Returns the column index against which this field is mapped.
|
AnnotatedElement |
getTarget()
Returns the
Field mapped to a column |
int |
hashCode() |
boolean |
isMappedToField()
Returns
true if the field is mapped to a column name, otherwise false |
boolean |
isMappedToIndex()
Returns
true if the field is mapped to a column index, otherwise false |
Object |
read(Object instance)
Reads the value accessible by this field mapping from a given object
|
void |
setFieldName(NormalizedString fieldName)
Defines the column name against which this field is mapped, overriding any current name derived from
annotations or from the attribute name itself.
|
void |
setFieldName(String fieldName)
Defines the column name against which this field is mapped, overriding any current name derived from
annotations or from the attribute name itself.
|
void |
setIndex(int index)
Defines the column index against which this field is mapped, overriding any current position derived from
annotations.
|
String |
toString() |
void |
write(Object instance,
Object value)
Writes a value to the field of a given object instance, whose field is accessible through this field mapping.
|
public FieldMapping(Class<?> beanClass, AnnotatedElement target, PropertyWrapper property, HeaderTransformer transformer, NormalizedString[] headers)
beanClass
- the class that contains a the given field.target
- a Field
or Method
annotated with Parsed
property
- the property descriptor of this field, if any. If this bean does not have getters/setters, it will be accessed directly.transformer
- an optional HeaderTransformer
to modify header names/positions in attributes of Nested
classes.headers
- list of headers parsed from the input or manually set with CommonSettings.setHeaders(String...)
public boolean isMappedToIndex()
true
if the field is mapped to a column index, otherwise false
true
if the field is mapped to a column index, otherwise false
public boolean isMappedToField()
true
if the field is mapped to a column name, otherwise false
true
if the field is mapped to a column name, otherwise false
public int getIndex()
public void setIndex(int index)
index
- the column index associated with this fieldpublic void setFieldName(String fieldName)
fieldName
- the column name associated with this fieldpublic void setFieldName(NormalizedString fieldName)
fieldName
- the column name associated with this fieldpublic NormalizedString getFieldName()
null
if there's no such association.public AnnotatedElement getTarget()
Field
mapped to a columnField
mapped to a columnpublic Class<?> getFieldParent()
public Class<?> getFieldType()
public boolean canWrite(Object instance)
instance
- the object whose type will be verified in order to identify if it contains the mapped fieldtrue
if the given instance contains the field/accessor method and can use this field mapping to modify its internal state; otherwise false
public Object read(Object instance)
instance
- the object whose field, mapped by this field mapping, will be readpublic void write(Object instance, Object value)
instance
- the object whose field will be setvalue
- the value to set on the given object's field.Copyright © 2019 Univocity Software Pty Ltd. All rights reserved.