Search in sources :

Example 26 with BeanProperty

use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.

the class TypeDescriptorTests method nestedPropertyTypeMapTwoLevels.

@Test
public void nestedPropertyTypeMapTwoLevels() throws Exception {
    final BeanProperty property = BeanProperty.valueOf(getClass(), "test4");
    TypeDescriptor t1 = TypeDescriptor.nested(property.getField(), 2);
    assertThat(t1.getType()).isEqualTo(String.class);
}
Also used : BeanProperty(cn.taketoday.beans.BeanProperty) Test(org.junit.jupiter.api.Test)

Example 27 with BeanProperty

use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.

the class TypeDescriptorTests method propertyGenericTypeList.

@Test
void propertyGenericTypeList() throws Exception {
    GenericType<Integer> genericBean = new IntegerType();
    BeanProperty property = BeanProperty.valueOf(genericBean.getClass().getMethod("getListProperty"), genericBean.getClass().getMethod("setListProperty", List.class));
    TypeDescriptor desc = property.getTypeDescriptor();
    assertThat(desc.getType()).isEqualTo(List.class);
    assertThat(desc.getElementDescriptor().getType()).isEqualTo(Integer.class);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BeanProperty(cn.taketoday.beans.BeanProperty) Test(org.junit.jupiter.api.Test)

Example 28 with BeanProperty

use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.

the class TypeDescriptorTests method propertyComplex.

@Test
public void propertyComplex() throws Exception {
    BeanProperty complexProperty = BeanProperty.valueOf(getClass(), "complexProperty");
    TypeDescriptor desc = complexProperty.getTypeDescriptor();
    assertThat(desc.getMapKeyDescriptor().getType()).isEqualTo(String.class);
    assertThat(desc.getMapValueDescriptor().getElementDescriptor().getElementDescriptor().getType()).isEqualTo(Integer.class);
}
Also used : BeanProperty(cn.taketoday.beans.BeanProperty) Test(org.junit.jupiter.api.Test)

Example 29 with BeanProperty

use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.

the class TypeDescriptorTests method upCastNotSuper.

@Test
public void upCastNotSuper() throws Exception {
    final BeanProperty property = BeanProperty.valueOf(getClass(), "property");
    TypeDescriptor descriptor = property.getTypeDescriptor();
    assertThatIllegalArgumentException().isThrownBy(() -> descriptor.upcast(Collection.class)).withMessage("interface java.util.Map is not assignable to interface java.util.Collection");
}
Also used : BeanProperty(cn.taketoday.beans.BeanProperty) Test(org.junit.jupiter.api.Test)

Example 30 with BeanProperty

use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.

the class BeanPropertyRowMapper method initialize.

protected void initialize(Class<T> mappedClass, BeanMetadata metadata) {
    this.mappedClass = mappedClass;
    setConversionService(ApplicationConversionService.getSharedInstance());
    HashSet<String> mappedProperties = new HashSet<>();
    HashMap<String, BeanProperty> mappedFields = new HashMap<>();
    for (BeanProperty property : metadata) {
        if (property.isWriteable()) {
            String lowerCaseName = lowerCaseName(property.getName());
            mappedFields.put(lowerCaseName, property);
            String underscoreName = underscoreName(property.getName());
            if (!lowerCaseName.equals(underscoreName)) {
                mappedFields.put(underscoreName, property);
            }
            mappedProperties.add(property.getName());
        }
    }
    this.mappedFields = mappedFields;
    this.mappedProperties = mappedProperties;
}
Also used : HashMap(java.util.HashMap) HashSet(java.util.HashSet) BeanProperty(cn.taketoday.beans.BeanProperty)

Aggregations

BeanProperty (cn.taketoday.beans.BeanProperty)42 Test (org.junit.jupiter.api.Test)22 JdbcBeanMetadata (cn.taketoday.jdbc.result.JdbcBeanMetadata)8 BeanWrapperImpl (cn.taketoday.beans.BeanWrapperImpl)6 ArrayList (java.util.ArrayList)6 List (java.util.List)4 BeanMetadata (cn.taketoday.beans.BeanMetadata)2 NotWritablePropertyException (cn.taketoday.beans.NotWritablePropertyException)2 SimpleTypeConverter (cn.taketoday.beans.SimpleTypeConverter)2 TypeMismatchException (cn.taketoday.beans.TypeMismatchException)2 PropertyAccessor (cn.taketoday.core.reflect.PropertyAccessor)2 DataRetrievalFailureException (cn.taketoday.dao.DataRetrievalFailureException)2 InvalidDataAccessApiUsageException (cn.taketoday.dao.InvalidDataAccessApiUsageException)2 Method (java.lang.reflect.Method)2 ResultSet (java.sql.ResultSet)2 ResultSetMetaData (java.sql.ResultSetMetaData)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2