Use @RawData for fetching too, oops
This commit is contained in:
parent
a5d7837c7d
commit
bd8e3b284b
@ -61,7 +61,7 @@ public class Document<V> {
|
|||||||
public Document(@NonNull Object element) {
|
public Document(@NonNull Object element) {
|
||||||
Class<?> clazz = element.getClass(); // Get the element class
|
Class<?> clazz = element.getClass(); // Get the element class
|
||||||
String idKey = null; // The key for the id field
|
String idKey = null; // The key for the id field
|
||||||
java.lang.reflect.Field rawDataField = null;
|
java.lang.reflect.Field rawDataField = null; // The raw data field if defined
|
||||||
for (java.lang.reflect.Field field : clazz.getDeclaredFields()) {
|
for (java.lang.reflect.Field field : clazz.getDeclaredFields()) {
|
||||||
// Raw data field, save it for later
|
// Raw data field, save it for later
|
||||||
if (field.isAnnotationPresent(RawData.class)) {
|
if (field.isAnnotationPresent(RawData.class)) {
|
||||||
|
@ -10,6 +10,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import me.braydon.feather.FeatherSettings;
|
import me.braydon.feather.FeatherSettings;
|
||||||
|
import me.braydon.feather.annotation.RawData;
|
||||||
import me.braydon.feather.annotation.Serializable;
|
import me.braydon.feather.annotation.Serializable;
|
||||||
import me.braydon.feather.common.FieldUtils;
|
import me.braydon.feather.common.FieldUtils;
|
||||||
|
|
||||||
@ -121,7 +122,14 @@ public abstract class Repository<D extends IDatabase<?, ?>, ID, E> {
|
|||||||
E entity = constructor.newInstance(); // Create the entity
|
E entity = constructor.newInstance(); // Create the entity
|
||||||
|
|
||||||
// Get the field tagged with @Field
|
// Get the field tagged with @Field
|
||||||
|
java.lang.reflect.Field rawDataField = null; // The raw data field if defined
|
||||||
for (Field field : entityClass.getDeclaredFields()) {
|
for (Field field : entityClass.getDeclaredFields()) {
|
||||||
|
// Raw data field, save it for later
|
||||||
|
if (field.isAnnotationPresent(RawData.class)) {
|
||||||
|
rawDataField = field;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Not the field we're looking for
|
// Not the field we're looking for
|
||||||
if (!field.isAnnotationPresent(me.braydon.feather.annotation.Field.class)) {
|
if (!field.isAnnotationPresent(me.braydon.feather.annotation.Field.class)) {
|
||||||
continue;
|
continue;
|
||||||
@ -141,6 +149,10 @@ public abstract class Repository<D extends IDatabase<?, ?>, ID, E> {
|
|||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
field.set(entity, value);
|
field.set(entity, value);
|
||||||
}
|
}
|
||||||
|
if (rawDataField != null) { // We have a raw data field, set it
|
||||||
|
rawDataField.setAccessible(true); // Make our field accessible
|
||||||
|
rawDataField.set(entity, mappedData); // Set the raw data field to our mapped document
|
||||||
|
}
|
||||||
return entity;
|
return entity;
|
||||||
} catch (NoSuchMethodException ex) { // We need our no args constructor
|
} catch (NoSuchMethodException ex) { // We need our no args constructor
|
||||||
throw new IllegalStateException("Entity " + entityClass.getName() + " is missing no args constructor");
|
throw new IllegalStateException("Entity " + entityClass.getName() + " is missing no args constructor");
|
||||||
|
Loading…
Reference in New Issue
Block a user