Example usage for java.beans PropertyDescriptor getPropertyType

List of usage examples for java.beans PropertyDescriptor getPropertyType

Introduction

In this page you can find the example usage for java.beans PropertyDescriptor getPropertyType.

Prototype

public synchronized Class<?> getPropertyType() 

Source Link

Document

Returns the Java type info for the property.

Usage

From source file:grails.util.GrailsClassUtils.java

/**
 * Retrieves a PropertyDescriptor for the specified instance and property value
 *
 * @param instance The instance/*from   w  w w.  j  a v  a2  s.co m*/
 * @param propertyValue The value of the property
 * @return The PropertyDescriptor
 */
public static PropertyDescriptor getPropertyDescriptorForValue(Object instance, Object propertyValue) {
    if (instance == null || propertyValue == null) {
        return null;
    }

    PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(instance.getClass());
    for (PropertyDescriptor pd : descriptors) {
        if (isAssignableOrConvertibleFrom(pd.getPropertyType(), propertyValue.getClass())) {
            Object value;
            try {
                ReflectionUtils.makeAccessible(pd.getReadMethod());
                value = pd.getReadMethod().invoke(instance);
            } catch (Exception e) {
                throw new FatalBeanException("Problem calling readMethod of " + pd, e);
            }
            if (propertyValue.equals(value)) {
                return pd;
            }
        }
    }
    return null;
}

From source file:grails.util.GrailsClassUtils.java

/**
 * Retrieves a property of the given class of the specified name and type
 * @param clazz The class to retrieve the property from
 * @param propertyName The name of the property
 * @param propertyType The type of the property
 *
 * @return A PropertyDescriptor instance or null if none exists
 *///  w  w w  .jav  a  2 s .  c  o m
public static PropertyDescriptor getProperty(Class<?> clazz, String propertyName, Class<?> propertyType) {
    if (clazz == null || propertyName == null || propertyType == null) {
        return null;
    }

    try {
        PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(clazz, propertyName);
        if (pd != null && pd.getPropertyType().equals(propertyType)) {
            return pd;
        }
        return null;
    } catch (Exception e) {
        // if there are any errors in instantiating just return null for the moment
        return null;
    }
}

From source file:com.espertech.esperio.SendableBeanEvent.java

/**
 * Converts mapToSend to an instance of beanClass
 * @param mapToSend - the map containing data to send into the runtime
 * @param beanClass  - type of the bean to create from mapToSend
 * @param eventTypeName - the event type name for the map event
 * @param timestamp - the timestamp for this event
 * @param scheduleSlot - the schedule slot for the entity that created this event
 *///from   w  w w .  j  a  v  a2  s .c o  m
public SendableBeanEvent(Map<String, Object> mapToSend, Class beanClass, String eventTypeName, long timestamp,
        ScheduleSlot scheduleSlot) {
    super(timestamp, scheduleSlot);

    try {
        beanToSend = beanClass.newInstance();
        // pre-create nested properties if any, as BeanUtils does not otherwise populate 'null' objects from their respective properties
        PropertyDescriptor[] pds = ReflectUtils.getBeanSetters(beanClass);
        for (PropertyDescriptor pd : pds) {
            if (!pd.getPropertyType().isPrimitive() && !pd.getPropertyType().getName().startsWith("java")) {
                BeanUtils.setProperty(beanToSend, pd.getName(), pd.getPropertyType().newInstance());
            }
        }
        // this method silently ignores read only properties on the dest bean but we should
        // have caught them in CSVInputAdapter.constructPropertyTypes.
        BeanUtils.copyProperties(beanToSend, mapToSend);
    } catch (Exception e) {
        throw new EPException("Cannot populate bean instance", e);
    }
}

From source file:grails.util.GrailsClassUtils.java

/**
 * Returns the type of the given property contained within the specified class
 *
 * @param clazz The class which contains the property
 * @param propertyName The name of the property
 *
 * @return The property type or null if none exists
 *//*from www  . j  a  v a2 s .com*/
public static Class<?> getPropertyType(Class<?> clazz, String propertyName) {
    if (clazz == null || !StringUtils.hasText(propertyName)) {
        return null;
    }

    try {
        PropertyDescriptor desc = BeanUtils.getPropertyDescriptor(clazz, propertyName);
        if (desc != null) {
            return desc.getPropertyType();
        }
        return null;
    } catch (Exception e) {
        // if there are any errors in instantiating just return null for the moment
        return null;
    }
}

From source file:com.puppycrawl.tools.checkstyle.internal.XdocsPagesTest.java

private static void validatePropertySectionProperties(String fileName, String sectionName, Node subSection,
        Object instance, Set<String> properties) throws Exception {
    boolean skip = true;
    boolean didJavadocTokens = false;
    boolean didTokens = false;

    for (Node row : XmlUtil.getChildrenElements(XmlUtil.getFirstChildElement(subSection))) {
        if (skip) {
            skip = false;//from w w  w. ja  v a 2s  .  co m
            continue;
        }
        Assert.assertFalse(fileName + " section '" + sectionName + "' should have token properties last",
                didTokens);

        final List<Node> columns = new ArrayList<>(XmlUtil.getChildrenElements(row));

        final String propertyName = columns.get(0).getTextContent();
        Assert.assertTrue(
                fileName + " section '" + sectionName + "' should not contain the property: " + propertyName,
                properties.remove(propertyName));

        if ("tokens".equals(propertyName)) {
            final AbstractCheck check = (AbstractCheck) instance;
            validatePropertySectionPropertyTokens(fileName, sectionName, check, columns);
            didTokens = true;
        } else if ("javadocTokens".equals(propertyName)) {
            final AbstractJavadocCheck check = (AbstractJavadocCheck) instance;
            validatePropertySectionPropertyJavadocTokens(fileName, sectionName, check, columns);
            didJavadocTokens = true;
        } else {
            Assert.assertFalse(
                    fileName + " section '" + sectionName
                            + "' should have javadoc token properties next to last, before tokens",
                    didJavadocTokens);
            Assert.assertFalse(
                    fileName + " section '" + sectionName + "' should have a description for " + propertyName,
                    columns.get(1).getTextContent().trim().isEmpty());

            final String actualTypeName = columns.get(2).getTextContent().replace("\n", "").replace("\r", "")
                    .replaceAll(" +", " ").trim();
            final String actualValue = columns.get(3).getTextContent().replace("\n", "").replace("\r", "")
                    .replaceAll(" +", " ").trim();

            Assert.assertFalse(
                    fileName + " section '" + sectionName + "' should have a type for " + propertyName,
                    actualTypeName.isEmpty());

            final PropertyDescriptor descriptor = PropertyUtils.getPropertyDescriptor(instance, propertyName);
            final Class<?> clss = descriptor.getPropertyType();
            final String expectedTypeName = getModulePropertyExpectedTypeName(clss, instance, propertyName);
            final String expectedValue = getModulePropertyExpectedValue(clss, instance, propertyName);

            if (expectedTypeName != null) {
                Assert.assertEquals(
                        fileName + " section '" + sectionName + "' should have the type for " + propertyName,
                        expectedTypeName, actualTypeName);
                if (expectedValue != null) {
                    Assert.assertEquals(fileName + " section '" + sectionName + "' should have the value for "
                            + propertyName, expectedValue, actualValue);
                }
            }
        }
    }
}

From source file:org.pentaho.platform.engine.services.solution.ActionBeanUtil.java

public Class<?> getClass(Object bean, String name)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    PropertyDescriptor desc = propUtil.getPropertyDescriptor(bean, name);
    return desc.getPropertyType();
}

From source file:jp.go.nict.langrid.p2pgridbasis.data.langrid.converter.ConvertUtil.java

static public DataAttributes encode(Object data) throws DataConvertException {
    setLangridConverter();/*from   w ww  .  ja  va  2  s . c  om*/
    logger.debug("##### encode #####");
    try {
        DataAttributes attr = new DataAttributes();
        for (PropertyDescriptor descriptor : PropertyUtils.getPropertyDescriptors(data)) {
            if (PropertyUtils.isReadable(data, descriptor.getName())) {
                if (descriptor.getName().equalsIgnoreCase("supportedLanguages")) {
                    //supportedLanguages
                    attr.setAttribute(descriptor.getName(),
                            (String) converter.lookup(descriptor.getPropertyType()).convert(String.class,
                                    PropertyUtils.getProperty(data, descriptor.getName())));
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("instance")) {
                    // 
                    // 
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("wsdl")) {
                    // 
                    // 
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("interfaceDefinitions")) {
                    // 
                    // 
                    ServiceType type = (ServiceType) data;
                    Map<String, ServiceInterfaceDefinition> map = new HashMap<String, ServiceInterfaceDefinition>();
                    map = type.getInterfaceDefinitions();
                    String str = "";

                    try {
                        for (ServiceInterfaceDefinition s : map.values()) {
                            str = str + "ProtocolId=" + s.getProtocolId() + "\n";
                            str = str + "Definition="
                                    + Base64.encode(StreamUtil.readAsBytes(s.getDefinition().getBinaryStream()))
                                    + "\n";
                            str = str + "###ServiceInterfaceDefinition###\n";
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }

                    attr.setAttribute("interfaceDefinition_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("allowedAppProvision")) {
                    Service s = (Service) data;
                    String value = "";
                    for (String str : s.getAllowedAppProvision()) {
                        value = value + str + "\n";
                    }
                    attr.setAttribute("allowedAppProvision", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("allowedUse")) {
                    Service s = (Service) data;
                    String value = "";
                    for (String str : s.getAllowedUse()) {
                        value = value + str + "\n";
                    }
                    attr.setAttribute("allowedUse", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("supportedDomains")) {
                    Grid g = (Grid) data;
                    List<Domain> list = g.getSupportedDomains();
                    String value = "";
                    for (Domain d : list) {
                        value = value + d.getDomainId() + "\n";
                    }
                    attr.setAttribute("supportedDomain_list", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("partnerServiceNamespaceURIs")) {
                    //partnerServiceNamespaceURIs
                    BPELService s = (BPELService) data;
                    List<String> list = s.getPartnerServiceNamespaceURIs();
                    String value = "";
                    for (String str : list) {
                        value = value + str + "\n";
                    }
                    attr.setAttribute("partnerServiceNamespaceURI_list", value);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("serviceDeployments")) {
                    //ServiceDeployment
                    Service s = (Service) data;
                    String str = "";
                    for (ServiceDeployment sd : s.getServiceDeployments()) {
                        str = str + "GridId=" + sd.getGridId() + "\n";
                        str = str + "ServiceId=" + sd.getServiceId() + "\n";
                        str = str + "NodeId=" + sd.getNodeId() + "\n";
                        str = str + "ServicePath=" + sd.getServicePath() + "\n";
                        str = str + "Enabled=" + String.valueOf(sd.isEnabled()) + "\n";
                        str = str + "CreateTime=" + String.valueOf(sd.getCreatedDateTime().getTimeInMillis())
                                + "\n";
                        str = str + "UpdateTime=" + String.valueOf(sd.getUpdatedDateTime().getTimeInMillis())
                                + "\n";
                        if (sd.getDisabledByErrorDate() != null) {
                            str = str + "ErrorDate="
                                    + String.valueOf(sd.getDisabledByErrorDate().getTimeInMillis()) + "\n";
                        }
                        if (sd.getDeployedDateTime() != null) {
                            str = str + "DeployedTime="
                                    + String.valueOf(sd.getDeployedDateTime().getTimeInMillis()) + "\n";
                        }
                        str = str + "###ServiceDeployment###\n";
                    }
                    attr.setAttribute("deployment_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("serviceEndpoints")) {
                    //ServiceEndpoint
                    StringBuilder str = new StringBuilder();
                    Service s = (Service) data;
                    for (ServiceEndpoint se : s.getServiceEndpoints()) {
                        str.append("GridId=" + se.getGridId() + "\n");
                        str.append("ProtocolId=" + se.getProtocolId() + "\n");
                        str.append("ServiceId=" + se.getServiceId() + "\n");
                        str.append("Enabled=" + String.valueOf(se.isEnabled()) + "\n");
                        str.append("Url=" + se.getUrl().toString() + "\n");
                        str.append("AuthUserName=" + se.getAuthUserName() + "\n");
                        str.append("AuthPassword=" + se.getAuthPassword() + "\n");
                        str.append("DisableReason=" + se.getDisableReason() + "\n");
                        str.append("CreateTime=" + String.valueOf(se.getCreatedDateTime().getTimeInMillis())
                                + "\n");
                        str.append("UpdateTime=" + String.valueOf(se.getUpdatedDateTime().getTimeInMillis())
                                + "\n");
                        if (se.getDisabledByErrorDate() != null) {
                            str.append("ErrorDate="
                                    + String.valueOf(se.getDisabledByErrorDate().getTimeInMillis()) + "\n");
                        }
                        str.append("###ServiceEndpoint###\n");
                    }
                    attr.setAttribute("endpoint_list", str.toString());
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("invocations")) {
                    //Invocation
                    String str = "";
                    Service s = (Service) data;
                    for (Invocation in : s.getInvocations()) {
                        str = str + "InvocationName=" + in.getInvocationName() + "\n";
                        str = str + "OwnerServiceGridId=" + in.getOwnerServiceGridId() + "\n";
                        str = str + "OwnerServiceId=" + in.getOwnerServiceId() + "\n";
                        str = str + "ServiceGridId=" + in.getServiceGridId() + "\n";
                        str = str + "ServiceId=" + in.getServiceId() + "\n";
                        str = str + "ServiceName=" + in.getServiceName() + "\n";
                        str = str + "CreateTime=" + String.valueOf(in.getCreatedDateTime().getTimeInMillis())
                                + "\n";
                        str = str + "UpdateTime=" + String.valueOf(in.getUpdatedDateTime().getTimeInMillis())
                                + "\n";
                        str = str + "###Invocation###\n";
                    }
                    attr.setAttribute("invocations_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("metaAttributes")) {
                    //metaAttributes
                    String str = "";
                    if (data.getClass().getName().endsWith("ResourceType")) {
                        ResourceType r = (ResourceType) data;
                        for (ResourceMetaAttribute a : r.getMetaAttributes().values()) {
                            str = str + "DomainId=" + a.getDomainId() + "\n";
                            str = str + "AttributeId=" + a.getAttributeId() + "\n";
                            str = str + "###MetaAttribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("ServiceType")) {
                        ServiceType s = (ServiceType) data;
                        for (ServiceMetaAttribute a : s.getMetaAttributes().values()) {
                            str = str + "DomainId=" + a.getDomainId() + "\n";
                            str = str + "AttributeId=" + a.getAttributeId() + "\n";
                            str = str + "###MetaAttribute###\n";
                        }
                    } else {
                        logger.info("metaAttributes : " + data.getClass().getName());
                    }
                    attr.setAttribute("metaAttribute_list", str);
                    continue;
                } else if (descriptor.getName().equalsIgnoreCase("attributes")) {
                    //attribute
                    String str = "";
                    if (data.getClass().getName().endsWith("User")) {
                        User u = (User) data;
                        for (UserAttribute a : u.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getUserId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Service")) {
                        Service s = (Service) data;
                        for (ServiceAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getServiceId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Node")) {
                        Node s = (Node) data;
                        for (NodeAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getNodeId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Grid")) {
                        Grid s = (Grid) data;
                        for (GridAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    } else if (data.getClass().getName().endsWith("Resource")) {
                        Resource s = (Resource) data;
                        for (ResourceAttribute a : s.getAttributes()) {
                            str = str + "attribute_GridId=" + a.getGridId() + "\n";
                            str = str + "attribute_Id=" + a.getResourceId() + "\n";
                            str = str + "attribute_Name=" + a.getName() + "\n";
                            str = str + "attribute_Value=" + a.getValue() + "\n";
                            str = str + "attribute_CreateTime="
                                    + String.valueOf(a.getCreatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "attribute_UpdateTime="
                                    + String.valueOf(a.getUpdatedDateTime().getTimeInMillis()) + "\n";
                            str = str + "###Attribute###\n";
                        }
                    }
                    attr.setAttribute("attribute_list", str);
                    continue;
                } else if (data instanceof Service && (descriptor.getName().equals("alternateServiceId")
                        || descriptor.getName().equals("useAlternateServices"))) {
                    // 
                    // 
                    continue;
                }

                //Read OK
                if (data instanceof BPELService && descriptor.getName().equals("transferExecution")) {
                    // ignore
                } else {
                    attr.setAttribute(descriptor.getName(), BeanUtils.getProperty(data, descriptor.getName()));
                }
            } else if (descriptor.getPropertyType().isArray()) {
                logger.debug("name : " + descriptor.getName() + " isArray");
                // 
                // 
                attr.setAttribute(descriptor.getName(), (String) converter.lookup(descriptor.getPropertyType())
                        .convert(String.class, PropertyUtils.getProperty(data, descriptor.getName())));
            } else {
                logger.debug("Name : " + descriptor.getName());
                for (Method m : data.getClass().getMethods()) {
                    if (m.getName().equalsIgnoreCase("get" + descriptor.getName())
                            || m.getName().equalsIgnoreCase("is" + descriptor.getName())) {
                        if (m.getParameterTypes().length != 0) {
                            // 
                            // 
                            logger.debug("class : " + data.getClass().getName());
                            logger.debug("?:Skip");
                            break;
                        } else {
                            // 
                            // 
                            logger.debug("value : " + m.invoke(data));
                        }
                        attr.setAttribute(descriptor.getName(), m.invoke(data).toString());
                        break;
                    }
                }
            }
        }
        return attr;
    } catch (InvocationTargetException e) {
        throw new DataConvertException(e);
    } catch (IllegalArgumentException e) {
        throw new DataConvertException(e);
    } catch (IllegalAccessException e) {
        throw new DataConvertException(e);
    } catch (NoSuchMethodException e) {
        throw new DataConvertException(e);
    }
}

From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanPropertyDescriptorBindableInfo.java

public BeanPropertyDescriptorBindableInfo(BeanSupport beanSupport, IObserveInfo parent,
        PropertyDescriptor descriptor) throws Exception {
    super(beanSupport, parent, descriptor.getPropertyType(), createReference(parent, descriptor.getName()),
            createPresentation(parent, descriptor.getName(), descriptor.getPropertyType()));
    m_descriptor = descriptor;//from   w  ww  .jav a2s . co  m
}

From source file:com.swingtech.commons.util.ClassUtil.java

public static Class getPropertyType(final Class clazz, final String propertyName) {
    PropertyDescriptor[] propertyDescriptorList = null;
    PropertyDescriptor propertyDescriptor = null;

    if (clazz == null) {
        throw new IllegalArgumentException("clazz is null");
    }//from  w ww . ja v a  2  s. co m

    if (propertyName == null) {
        throw new IllegalArgumentException("propertyName is null");
    }

    propertyDescriptorList = PropertyUtils.getPropertyDescriptors(clazz);

    for (int i = 0; i < propertyDescriptorList.length; i++) {
        propertyDescriptor = propertyDescriptorList[i];

        if (propertyDescriptor.getName().equalsIgnoreCase(propertyName)) {
            return propertyDescriptor.getPropertyType();
        }
    }

    return null;
}

From source file:com.ms.commons.summer.web.util.json.JsonBeanUtils.java

/**
 * Creates a bean from a JSONObject, with the specific configuration.
 *//* w ww. j a v  a  2s . co m*/
public static Object toBean(JSONObject jsonObject, JsonConfig jsonConfig) {
    if (jsonObject == null || jsonObject.isNullObject()) {
        return null;
    }

    Class beanClass = jsonConfig.getRootClass();
    Map classMap = jsonConfig.getClassMap();

    if (beanClass == null) {
        return toBean(jsonObject);
    }
    if (classMap == null) {
        classMap = Collections.EMPTY_MAP;
    }

    Object bean = null;
    try {
        if (beanClass.isInterface()) {
            if (!Map.class.isAssignableFrom(beanClass)) {
                throw new JSONException("beanClass is an interface. " + beanClass);
            } else {
                bean = new HashMap();
            }
        } else {
            bean = jsonConfig.getNewBeanInstanceStrategy().newInstance(beanClass, jsonObject);
        }
    } catch (JSONException jsone) {
        throw jsone;
    } catch (Exception e) {
        throw new JSONException(e);
    }

    Map props = JSONUtils.getProperties(jsonObject);
    PropertyFilter javaPropertyFilter = jsonConfig.getJavaPropertyFilter();
    for (Iterator entries = jsonObject.names().iterator(); entries.hasNext();) {
        String name = (String) entries.next();
        Class type = (Class) props.get(name);
        Object value = jsonObject.get(name);
        if (javaPropertyFilter != null && javaPropertyFilter.apply(bean, name, value)) {
            continue;
        }
        String key = Map.class.isAssignableFrom(beanClass)
                && jsonConfig.isSkipJavaIdentifierTransformationInMapKeys() ? name
                        : JSONUtils.convertToJavaIdentifier(name, jsonConfig);
        try {
            if (Map.class.isAssignableFrom(beanClass)) {
                // no type info available for conversion
                if (JSONUtils.isNull(value)) {
                    setProperty(bean, key, value, jsonConfig);
                } else if (value instanceof JSONArray) {
                    setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig, name,
                            classMap, List.class), jsonConfig);
                } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                        || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                        || JSONFunction.class.isAssignableFrom(type)) {
                    if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) {
                        setProperty(bean, key, null, jsonConfig);
                    } else {
                        setProperty(bean, key, value, jsonConfig);
                    }
                } else {
                    Class targetClass = findTargetClass(key, classMap);
                    targetClass = targetClass == null ? findTargetClass(name, classMap) : targetClass;
                    JsonConfig jsc = jsonConfig.copy();
                    jsc.setRootClass(targetClass);
                    jsc.setClassMap(classMap);
                    if (targetClass != null) {
                        setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                    } else {
                        setProperty(bean, key, toBean((JSONObject) value), jsonConfig);
                    }
                }
            } else {
                PropertyDescriptor pd = PropertyUtils.getPropertyDescriptor(bean, key);
                if (pd != null && pd.getWriteMethod() == null) {
                    log.warn("Property '" + key + "' has no write method. SKIPPED.");
                    continue;
                }

                if (pd != null) {
                    Class targetType = pd.getPropertyType();
                    if (!JSONUtils.isNull(value)) {
                        if (value instanceof JSONArray) {
                            if (List.class.isAssignableFrom(pd.getPropertyType())) {
                                setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig,
                                        name, classMap, pd.getPropertyType()), jsonConfig);
                            } else if (Set.class.isAssignableFrom(pd.getPropertyType())) {
                                setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig,
                                        name, classMap, pd.getPropertyType()), jsonConfig);
                            } else {
                                setProperty(bean, key, convertPropertyValueToArray(key, value, targetType,
                                        jsonConfig, classMap), jsonConfig);
                            }
                        } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                                || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                                || JSONFunction.class.isAssignableFrom(type)) {
                            if (pd != null) {
                                if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) {
                                    setProperty(bean, key, null, jsonConfig);
                                } else if (!targetType.isInstance(value)) {
                                    setProperty(bean, key, morphPropertyValue(key, value, type, targetType),
                                            jsonConfig);
                                } else {
                                    setProperty(bean, key, value, jsonConfig);
                                }
                            } else if (beanClass == null || bean instanceof Map) {
                                setProperty(bean, key, value, jsonConfig);
                            } else {
                                log.warn("Tried to assign property " + key + ":" + type.getName()
                                        + " to bean of class " + bean.getClass().getName());
                            }
                        } else {
                            if (jsonConfig.isHandleJettisonSingleElementArray()) {
                                JSONArray array = new JSONArray().element(value, jsonConfig);
                                Class newTargetClass = findTargetClass(key, classMap);
                                newTargetClass = newTargetClass == null ? findTargetClass(name, classMap)
                                        : newTargetClass;
                                JsonConfig jsc = jsonConfig.copy();
                                jsc.setRootClass(newTargetClass);
                                jsc.setClassMap(classMap);
                                if (targetType.isArray()) {
                                    setProperty(bean, key, JSONArray.toArray(array, jsc), jsonConfig);
                                } else if (JSONArray.class.isAssignableFrom(targetType)) {
                                    setProperty(bean, key, array, jsonConfig);
                                } else if (List.class.isAssignableFrom(targetType)
                                        || Set.class.isAssignableFrom(targetType)) {
                                    jsc.setCollectionType(targetType);
                                    setProperty(bean, key, JSONArray.toCollection(array, jsc), jsonConfig);
                                } else {
                                    setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                                }
                            } else {
                                if (targetType == Object.class) {
                                    targetType = findTargetClass(key, classMap);
                                    targetType = targetType == null ? findTargetClass(name, classMap)
                                            : targetType;
                                }
                                JsonConfig jsc = jsonConfig.copy();
                                jsc.setRootClass(targetType);
                                jsc.setClassMap(classMap);
                                setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                            }
                        }
                    } else {
                        if (type.isPrimitive()) {
                            // assume assigned default value
                            log.warn("Tried to assign null value to " + key + ":" + type.getName());
                            setProperty(bean, key, JSONUtils.getMorpherRegistry().morph(type, null),
                                    jsonConfig);
                        } else {
                            setProperty(bean, key, null, jsonConfig);
                        }
                    }
                } else {
                    if (!JSONUtils.isNull(value)) {
                        if (value instanceof JSONArray) {
                            setProperty(bean, key, convertPropertyValueToCollection(key, value, jsonConfig,
                                    name, classMap, List.class), jsonConfig);
                        } else if (String.class.isAssignableFrom(type) || JSONUtils.isBoolean(type)
                                || JSONUtils.isNumber(type) || JSONUtils.isString(type)
                                || JSONFunction.class.isAssignableFrom(type)) {
                            if (pd != null) {
                                if (jsonConfig.isHandleJettisonEmptyElement() && "".equals(value)) {
                                    setProperty(bean, key, null, jsonConfig);
                                } else {
                                    setProperty(bean, key, value, jsonConfig);
                                }
                            } else if (beanClass == null || bean instanceof Map) {
                                setProperty(bean, key, value, jsonConfig);
                            } else {
                                log.warn("Tried to assign property " + key + ":" + type.getName()
                                        + " to bean of class " + bean.getClass().getName());
                            }
                        } else {
                            if (jsonConfig.isHandleJettisonSingleElementArray()) {
                                Class newTargetClass = findTargetClass(key, classMap);
                                newTargetClass = newTargetClass == null ? findTargetClass(name, classMap)
                                        : newTargetClass;
                                JsonConfig jsc = jsonConfig.copy();
                                jsc.setRootClass(newTargetClass);
                                jsc.setClassMap(classMap);
                                setProperty(bean, key, toBean((JSONObject) value, jsc), jsonConfig);
                            } else {
                                setProperty(bean, key, value, jsonConfig);
                            }
                        }
                    } else {
                        if (type.isPrimitive()) {
                            // assume assigned default value
                            log.warn("Tried to assign null value to " + key + ":" + type.getName());
                            setProperty(bean, key, JSONUtils.getMorpherRegistry().morph(type, null),
                                    jsonConfig);
                        } else {
                            setProperty(bean, key, null, jsonConfig);
                        }
                    }
                }
            }
        } catch (JSONException jsone) {
            throw jsone;
        } catch (Exception e) {
            throw new JSONException("Error while setting property=" + name + " type " + type, e);
        }
    }

    return bean;
}