use of org.simpleflatmapper.reflect.meta.PropertyMeta in project SimpleFlatMapper by arnaudroger.
the class SubPropertyMetaTest method testSubProperty.
@Test
@SuppressWarnings("unchecked")
public void testSubProperty() throws Exception {
ClassMeta<Db1DeepObject> classMeta = ReflectionService.newInstance().getClassMeta(Db1DeepObject.class);
PropertyMeta<Db1DeepObject, String> property = classMeta.newPropertyFinder(new Predicate<PropertyMeta<?, ?>>() {
@Override
public boolean test(PropertyMeta<?, ?> propertyMeta) {
return true;
}
}).findProperty(new DefaultPropertyNameMatcher("dbObject_name", 0, false, false), new Object[0]);
assertTrue(property instanceof SubPropertyMeta);
assertTrue(property.isSubProperty());
assertTrue(property.toString().startsWith("SubPropertyMeta{" + "ownerProperty=ObjectPropertyMeta{"));
SubPropertyMeta<Db1DeepObject, DbObject, String> subPropertyMeta = (SubPropertyMeta<Db1DeepObject, DbObject, String>) property;
assertEquals(String.class, subPropertyMeta.getPropertyType());
assertEquals("dbObject.name", subPropertyMeta.getPath());
Db1DeepObject object = new Db1DeepObject();
object.setDbObject(new DbObject());
subPropertyMeta.getSetter().set(object, "n1");
Getter<Db1DeepObject, String> getter = subPropertyMeta.getGetter();
assertEquals("n1", getter.get(object));
Db1DeepObject objectNull = new Db1DeepObject();
assertEquals(null, getter.get(objectNull));
assertTrue(getter.toString().startsWith("GetterOnGetter{g1="));
ClassMeta<?> meta = subPropertyMeta.getPropertyClassMeta();
assertEquals(String.class, meta.getType());
}
use of org.simpleflatmapper.reflect.meta.PropertyMeta in project SimpleFlatMapper by arnaudroger.
the class ArrayClassMetaTest method testArrayPrimitive.
private void testArrayPrimitive(Class<?> component, Object value) throws Exception {
assertTrue(component.isPrimitive());
Object array = Array.newInstance(component, 10);
ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(array.getClass());
assertTrue(classMeta instanceof ArrayClassMeta);
PropertyMeta p = classMeta.newPropertyFinder(new Predicate() {
@Override
public boolean test(Object propertyMeta) {
return true;
}
}).findProperty(DefaultPropertyNameMatcher.of("3"), new Object[0]);
p.getSetter().set(array, value);
assertEquals(value, p.getGetter().get(array));
assertEquals(value, Array.get(array, 3));
}
use of org.simpleflatmapper.reflect.meta.PropertyMeta in project SimpleFlatMapper by arnaudroger.
the class ArrayClassMetaTest method testGetterSetterOnList.
private Object testGetterSetterOnList(TypeReference<?> typeReference) throws Exception {
ClassMeta<?> classMeta = ReflectionService.newInstance().getClassMeta(typeReference.getType());
assertTrue(classMeta instanceof ArrayClassMeta);
PropertyMeta p = findProperty(classMeta);
Object list = instantiate(classMeta);
p.getSetter().set(list, "aaa");
assertEquals("aaa", p.getGetter().get(list));
return list;
}
use of org.simpleflatmapper.reflect.meta.PropertyMeta in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilder method fields.
@SuppressWarnings("unchecked")
private FieldMapper<S, T>[] fields() {
final List<FieldMapper<S, T>> fields = new ArrayList<FieldMapper<S, T>>();
propertyMappingsBuilder.forEachProperties(new ForEachCallBack<PropertyMapping<T, ?, K, FieldMapperColumnDefinition<K>>>() {
@Override
public void handle(PropertyMapping<T, ?, K, FieldMapperColumnDefinition<K>> t) {
if (t == null || isTargetForMapperFieldMapper(t))
return;
PropertyMeta<T, ?> meta = t.getPropertyMeta();
if (meta == null || (meta instanceof SelfPropertyMeta))
return;
if (!meta.isConstructorProperty() && !isTargetForMapperFieldMapper(t)) {
fields.add(newFieldMapper(t));
}
}
});
for (PropertyPerOwner e : getSubPropertyPerOwner()) {
if (!e.owner.isConstructorProperty()) {
final MappingContextFactoryBuilder currentBuilder = getMapperContextFactoryBuilder(e.owner, e.propertyMappings);
final Mapper<S, ?> mapper;
if (e.propertyMappings.size() == 1 && JoinUtils.isArrayElement(e.propertyMappings.get(0).getPropertyMeta())) {
mapper = getterPropertyMapper(e.owner, e.propertyMappings.get(0));
} else {
mapper = subPropertyMapper(e.owner, e.propertyMappings, currentBuilder);
}
fields.add(newMapperFieldMapper(e.propertyMappings, e.owner, mapper, currentBuilder));
}
}
for (FieldMapper<S, T> mapper : additionalMappers) {
fields.add(mapper);
}
return fields.toArray(new FieldMapper[0]);
}
Aggregations