public static Map<String, Object> toFlatMap(Object obj, Function<Object, Boolean> isNestedObject) { Map<String, Object> map = Maps.newHashMap(); BEAN_TO_MAP_CONVERTOR.flatObject("", obj, (k, v, ctx)->{ Object value = v; TypeDescriptor sourceType = null; if(v.getClass()!=String.class){ Field field = ctx.getField(); if(field!=null && (field.getAnnotation(DateTimeFormat.class)!=null || field.getAnnotation(NumberFormat.class)!=null) ){ sourceType = new TypeDescriptor(field); } if(sourceType==null){ sourceType = new TypeDescriptor(new Property(ctx.getSource().getClass(), ctx.getProperty().getReadMethod(), ctx.getProperty().getWriteMethod())); } value = getFormattingConversionService().convert(v, sourceType, TypeDescriptor.valueOf(String.class)); } map.put(k, value); }); return map; }
@Override public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { if (target == null) { return false; } Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass()); CacheKey cacheKey = new CacheKey(type, name, target instanceof Class); if (this.writerCache.containsKey(cacheKey)) { return true; } Method method = findSetterForProperty(name, type, target); if (method != null) { // Treat it like a property Property property = new Property(type, null, method); TypeDescriptor typeDescriptor = new TypeDescriptor(property); this.writerCache.put(cacheKey, method); this.typeDescriptorCache.put(cacheKey, typeDescriptor); return true; } else { Field field = findField(name, type, target); if (field != null) { this.writerCache.put(cacheKey, field); this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(field)); return true; } } return false; }
@Override public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { if (target == null) { return false; } Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass()); PropertyCacheKey cacheKey = new PropertyCacheKey(type, name, target instanceof Class); if (this.writerCache.containsKey(cacheKey)) { return true; } Method method = findSetterForProperty(name, type, target); if (method != null) { // Treat it like a property Property property = new Property(type, null, method); TypeDescriptor typeDescriptor = new TypeDescriptor(property); this.writerCache.put(cacheKey, method); this.typeDescriptorCache.put(cacheKey, typeDescriptor); return true; } else { Field field = findField(name, type, target); if (field != null) { this.writerCache.put(cacheKey, field); this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(field)); return true; } } return false; }
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { if (target == null) { return false; } Class<?> type = (target instanceof Class ? (Class<?>) target : target.getClass()); CacheKey cacheKey = new CacheKey(type, name, target instanceof Class); if (this.writerCache.containsKey(cacheKey)) { return true; } Method method = findSetterForProperty(name, type, target); if (method != null) { // Treat it like a property Property property = new Property(type, null, method); TypeDescriptor typeDescriptor = new TypeDescriptor(property); this.writerCache.put(cacheKey, method); this.typeDescriptorCache.put(cacheKey, typeDescriptor); return true; } else { Field field = findField(name, type, target); if (field != null) { this.writerCache.put(cacheKey, field); this.typeDescriptorCache.put(cacheKey, new TypeDescriptor(field)); return true; } } return false; }
private Property property(PropertyDescriptor pd) { GenericTypeAwarePropertyDescriptor typeAware = (GenericTypeAwarePropertyDescriptor) pd; return new Property(typeAware.getBeanClass(), typeAware.getReadMethod(), typeAware.getWriteMethod(), typeAware.getName()); }
private Property property(PropertyDescriptor pd) { GenericTypeAwarePropertyDescriptor gpd = (GenericTypeAwarePropertyDescriptor) pd; return new Property(gpd.getBeanClass(), gpd.getReadMethod(), gpd.getWriteMethod(), gpd.getName()); }
public static TypeDescriptor typeDescriptorForPerperty(Class<?> clazz, String propertyName){ PropertyDescriptor pd = ReflectUtils.getPropertyDescriptor(clazz, propertyName); TypeDescriptor td = new TypeDescriptor(new Property(clazz, pd.getReadMethod(), pd.getWriteMethod())); return td; }
/** * @return Property for property binder */ protected Property getProperty() { PropertyDescriptor pd = getPropertyDescriptor(); return new Property(getModel().getClass(), pd.getReadMethod(), pd.getWriteMethod()); }