tech.ydb.yoj.databind.schema.reflect.PojoField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yoj-databind Show documentation
Show all versions of yoj-databind Show documentation
Core data-binding logic used by YOJ (YDB ORM for Java) to convert
between Java objects and database rows (or anything representable by
a Java Map, really).
The newest version!
package tech.ydb.yoj.databind.schema.reflect;
import com.google.common.base.Preconditions;
import lombok.NonNull;
import tech.ydb.yoj.databind.schema.FieldValueException;
import javax.annotation.Nullable;
/**
* Represents a field of a POJO class, hand-written or generated e.g. by Lombok.
*/
public final class PojoField extends ReflectFieldBase {
private final java.lang.reflect.Field delegate;
public PojoField(@NonNull Reflector reflector, @NonNull java.lang.reflect.Field delegate) {
super(reflector, delegate.getName(), delegate.getGenericType(), delegate.getType(), delegate);
Preconditions.checkArgument(!delegate.isSynthetic(),
"Encountered a synthetic field, did you forget to declare the ID class as static? Field is: %s", delegate);
this.delegate = delegate;
this.delegate.setAccessible(true);
}
@Nullable
@Override
public Object getValue(Object containingObject) {
try {
return delegate.get(containingObject);
} catch (Exception e) {
throw new FieldValueException(e, getName(), containingObject);
}
}
@Override
public String toString() {
return "PojoField[" + getGenericType().getTypeName() + "::" + getName() + "]";
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy