List of usage examples for org.springframework.beans PropertyAccessor getPropertyType
@Nullable
Class<?> getPropertyType(String propertyName) throws BeansException;
From source file:com.nestedbird.modules.formparser.FormParse.java
/** * Write the value to the existingEntity field with the name of key * * @param <T> Type of the entity * @param existingEntity The entity we are changing * @param key The key we are changing * @param value The new value/* w w w.j av a2s .c o m*/ */ private <T extends BaseEntity> void writeToEntity(T existingEntity, String key, Object value) { final PropertyAccessor accessor = PropertyAccessorFactory.forDirectFieldAccess(existingEntity); if (accessor.getPropertyType(key) != null) { try { if (value.getClass().equals(JSONObject.class) && ((JSONObject) value).has("_isMap") && ((JSONObject) value).get("_isMap").equals(true)) { writeArrayMapToEntity(accessor, key, (JSONObject) value); } else if (value.getClass().equals(JSONObject.class)) { writeObjectToEntity(accessor, key, (JSONObject) value); } else if (value.getClass().equals(JSONArray.class)) { writeArrayToEntity(accessor, key, (JSONArray) value); } else if (isFieldValid(accessor, key, existingEntity.getClass())) { writeValueToEntity(accessor, key, value); } } catch (JSONException e) { logger.info("[FormParse] [writeToEntity] Unable To Process JSON", e); } } }
From source file:com.nestedbird.modules.formparser.FormParse.java
/** * Is field valid for editing//from w w w. j av a 2 s. c o m * * @param accessor the accessor * @param fieldName the field name * @param entityClass the entity class * @return the boolean */ private boolean isFieldValid(final PropertyAccessor accessor, final String fieldName, final Class entityClass) { return isFieldInteractable(accessor, fieldName) && isFieldEditable(accessor, fieldName) && doesSetterExist(entityClass, fieldName, accessor.getPropertyType(fieldName)) && !isFieldFinal(entityClass, fieldName); }